How to change an object itself, the pointer to object, create another object.
Array.prototype.change=function(b){
// this=b; //does not work
}
a=[1,2,3];
b=[3,2,1];
a.change(b);
console.log(a); // Should be [3,2,1]
Another example:
String.prototype.double=function(){
//this+=this; //like str+=str
}
str="hello";
str.double();
console.log(str); // echo "hellohello"
You can define your prototype like this:
Internally it will clear existing data and add data from array in parameter.
This will not make Array a exactly equal Array b (they will still be different objects with different references and
a == b
would befalse
) but data in both will be the same.