Javascript OOP: binding method to event handler [duplicate]-Collection of common programming errors
You found the one hole in Javascript’s implementation of closures. (If you don’t know what closures are, don’t worry about it.)
this
in Javascript references the object on which the function was called. So if you have an object with a property that happens to be assigned the value of a function, and you call that property, the this
pointer references the object. It does not reference whatever this
was where the function was created, nor does it reference the function itself.
var object = {};
object.myfunc = function() { console.log(this); } //