【发布时间】:2015-03-24 18:35:36
【问题描述】:
我有一个带有两个方法的 JavaScript 类,例如 this。
var MyObject = function () {};
MyObject.prototype = {
open: function () {
var self = this;
console.log(self);
$('#a').click('', self.other);
},
other: function () {
console.log(this);
}
};
var myobject = new MyObject;
myobject.open();
在other函数中的console.log中,this是事件监听的HTML节点,而不是MyObject对象,如open函数。
当用作回调时,如何从函数other 中检索MyObject 对象?
【问题讨论】:
标签: javascript jquery callback this