Friday, 15 May 2015

actionscript 3 - ActionScript3 - augmenting prototype of String -



actionscript 3 - ActionScript3 - augmenting prototype of String -

in as2 following:

string.prototype.startswith = function(s){ homecoming this.indexof(s) == 1 }

thus, startswith available on every string object

var s = "some string test with"; s.startswith("some") // returns true

and did great repository of cool tools:

var s = "some @var string"; s.startswith("some");//returns true s.endswith("ing");//returns true s.contains("@");//returns true s.databind({var: "awsome"})// returns 'some awsome string' s = "b"; s.isanyof("a","b","c"); //true, because "b" 1 of options s.isinarr(["a","b","c"]); //true, because "b" in passed array var o = { foo: function(i) { homecoming "wind " + } } s = "foo"; f.call(o,3) //returns "wind 3" because method foo ivoked on o 3 f.apply(o,[3]) //returns "wind 3" because method foo ivoked on o 3 var a1 = [], a2 = [] s.push(a1,a2) // pushes s a1 , a2

and on, , forth many cool things makes coding much more fun (and blazing fast when smartly used)

it's not string, have such utils number, date, boolean, , on.

here's tried:

[test] public function test_stringprototype() { string.prototype.startswith = function(s):boolean { homecoming return this.indexof(s) == 1; } asserttrue( !!string.prototype.startswith ) //and far - ! line passes var s:string = "some str"; asserttrue(!!o.startswith ) //and won't compile... :( }

and won't compile, not mention pass or fail test... error: access of perchance undefined property startswith through reference static type string.

whats way in as3?

yes of course, utilize string representation of variable name: "startswith"; illustration down

string.prototype.traceme = function():void { trace(this); } var s:string = "some str"; s["traceme"]();

else method:

var s:object = new string("some str"); s.traceme();

string actionscript-3 prototype

No comments:

Post a Comment