Javascript question: Problem with calling an objects methods -
Say I have an object called FieldEdit I define the function constructor for this object, Instant through it var obj = new FieldEdit ()
, and FieldEdit.prototype & Lt; Method Name & gt; = () {...}
. .
Under what circumstances would other methods of this object (this. <>> Name name.
Note that I would like to avoid posting a code sample for this, because I can think that it is a problem in my understanding of javascript compared to just a few, in fact I am pretty sure that My code is the best knowledge (and this is my knowledge, besides here the question is).
Most likely where this
FieldEdit
In addition to FieldEdit
, the object will reference an object called nested scope such as a closure, an event handler, or any function or method explicitly .call (someOtherScope)
Or .apply (someOtherScope, args)
.
You must maintain a variable reference for example FieldEditInstance. & Lt; Method & gt; ()
Instead.
PrototypeJs allows you to wrap the work with function.bind
for this purpose, but it can be easily accomplished otherwise, either:
var FieldEditInstance = this; Obj.methodThatUsesACallback (function () {// use it instead}};
or
var FieldEditInstance = this; Var callback = function () {// ...}; // function of prototype js which is more or less Bind has produced class bound Clawback = function (). (Return Callback. Apely (FieldEdit Instance, Arguments);}; obj.methodThatUsesACallback (boundCallback);
Comments
Post a Comment