Thursday, 22 August 2013

How to change this in object?

How to change this in object?

How to create method twice? I can't understand how to change this in body
of function. Why it doesn't work?
function twice() {
var buf = [];<br/>
for ( var i = 0; i < this.length; i++ ) {
buf.push(this[i]);
}
for ( var i = 0; i < this.length; i++ ) {
buf.push(this[i]);
}
this = buf;
}
Array.prototype.twice = twice;
a = [1,2,3];
a.twice();
a; // [1,2,3,1,2,3]

No comments:

Post a Comment