javascript callback scope


i'm carrying problem plain aged javascript (no frameworks) referencing vigilant callback function.



function foo(id) {
this.dom = document.getelementbyid(id);
this.bar = 5;
var self = this;
this.dom.addeventlistener("click", self.onclick, false);
}

foo.prototype = {
onclick : function() {
this.bar = 7;
}
};


now i emanate new vigilant (after dom loaded, span#test)



var x = new foo('test');


the 'this' inside onclick duty points span#test foo object.



how i anxiety foo vigilant inside onclick function?



Comments

Popular posts from this blog

list macos calm editors formula editors

how hibernate @any-related annotations?

using mvc, should hoop communication between views? between models?