Sorry if this has been answered, but I couldn't turn up a search for it... a difficult thing to search for, I think!
Say I have this:
var MyPrototype = function() { this.init(); }
$.extend(MyPrototype.prototype, {
a: 5,
init: function() {
var thing = new SomeOtherClass();
thing.meth = this.meth;
// thing.meth() is called somewhere within thing;
},
meth: function() {
alert(this.a);
}
}
Basically, I am dealing with another class which uses its own methods as callbacks, e.g. I am expected to override them with my own functionality. But I need to retain the proper scope of this
while doing it (the only thing I care about from SomeOtherClass
is what's passed to the callback; nothing in the state).
As you might imagine, this doesn't work because thing
has no a
property! I am not familiar enough with the intricacies of Javascript scoping to know how to make this
refer to what I want, though!