【发布时间】:2016-11-15 20:17:02
【问题描述】:
如果我有以下代码:
function Something() {
this.randomElement = $("#element");
}
Something.prototype = {
functionOne: function() {
console.log("hello");
},
functionTwo: function() {
this.randomElement.click(function(e) {
this.functionOne(); //this becomes pointed at randomElement
});
}
}
如何以简洁的方式编写此代码,而不必在 functionTwo 中使用 Something.prototype.functionOne() 替换 this.functionOne()?既然点击事件改变了this的值?
【问题讨论】:
标签: javascript jquery prototype-programming