So I have some javascript class and in one method I use jQuery to bind function to click event. And within this function I need to call other methods of this class. In usual js function I did it through "this.method_name()", but here, I guess, jQuery redefines "this" pointer.
Anu*_*rag 10
jQuery doesn't redefine the this pointer, but that's how JavaScript functions work in general. Store a reference to the this pointer under a different name, and use that.
var self = this;
$("selector").click(function() {
self.method_name();
});
Run Code Online (Sandbox Code Playgroud)
See this answer for more approaches.
| 归档时间: |
|
| 查看次数: |
16894 次 |
| 最近记录: |