I came across this bug and didn't find an example anywhere. Documenting here for reference.
The problem was that when calling o.callback() in the example below, the value of x changes between defining and executing the callback.
p = {
f: function () { x = 'p.f() local'; }
};
o = {
f: function () {
x = 'o.f() local';
this.callback = function () { console.log(x); };
}
};
o.f();
p.f();
o.callback.apply();
The output here is:
p.f() local
While I expected:
o.f() local
Update Here's a jsfiddle: http://jsfiddle.net/elplatt/kzS5A/1/