How can I maintain control of the this keyword when extending prototypes in jQuery? [duplicate]
问题 This question already has answers here : How to access the correct `this` inside a callback? (10 answers) Closed 4 years ago . I'm implementing a class-like structure in jQuery, but I'm having some trouble when I try to call some of my functions. This is how the structure is setup: MyClass = function(name) { this.init(name); } $.extend(MyClass.prototype, { init: function(theName) { this.myFunction(); // works $('.myclass').each(function(){ this.myFunction(); // doesn't work }); }, myFunction