object referring is confusing in Javascript. somehow, i came out with a piece of code

var u = {};
var x = y = z = {"cvalue":"cell", "call":function(){alert(this.cvalue);}};

(function(){u=x;/*change all cvalue in x,y, z, u*/ u.cvalue = "notcell";})();

if(u == x && x == y && y == z && z == u){
    u.call();
}

//only u goes to null
u = null;
//x,y,z stay same
alert(x.cvalue);

By u = null, only breaking the reference to the certain memory location(noticing not reference to “x”). Therefore, if x= null, u still referring to the memory and u.call() still works.

Advertisements