Consider the code:
window.a = function(x){
var r = x*2;
window.a =alert; // redefines itself after first call
return r;
};
a('2 * 2 = '+a(2)); // doesn't work. it should've alerted "2 * 2 = 4"
This doesn't work either:
window.a = function(x){
alert(x);
window.a = function(x){ // redefines itself after first call
var r = x*2;
return r;
}
};
a('2 * 2 = '+a(2)); // doesn't work. it should've alerted "2 * 2 = 4"
As neither does this:
window.a = function(x){ alert(x); window.c = window.a; window.a = window.b; window.b = window.c; };
window.b = function(x){ var r = x*2; window.c = window.b; window.b = window.a; window.a = window.c; return r; };
a('2 * 2 = '+a(2)); // doesn't work.
And basically I've tried all possible ways and neither seem to do the job. Can someone please explain why?
var r = a(2)
, and thena('2 * 2 = ' + r)
– Improbity