javascript - How to access a method of a closure's parent object? -
I have defined a class named MyClass
and I have defined two methods MyMethod1
and myMethod2
for:
function myClass () {} MyClass.prototype.myMethod1 = function () {...}; MyClass.prototype.myMethod2 = function () {...}; inside myMethod1
, I use jQuery and there is a callback ending defined:
MyClass.prototype. MyMethod2 = function () {$ .jQuery ({success: function} {this.myMethod2 ();}, ...}); }
The problem is that is not referring to
now MyClass
. The question is how can I refer to it? At the moment I have allocated it to a variable called thisObj
and used it like this:
MyClass.prototype.myMethod2 = function () {var thisObj = This; $ .jQuery ({success: function (data) {thisObj.myMethod2 ();}, ...}); }
Closing in myMethod2
is there a better way to reach MyClass.this
?
Thanks in advance.
The method you use is often called "that reference", because the name That
is usually used as the name of the copy of the this
reference, for example see Crockford talks on javascript.
html नमूना कोड
ReplyDeleteफ्लोट एक रिश्तेदार तैनात कंटेनर कोड नमूने में छोड़ दिया गया