var TestClass;if (TestClass == undefined) { TestClass = function(){
}
}TestClass.prototype.init = function (options) {
$(".alert_click").click(function(){ this.popup("test"); //这样的代码会提示popup未定义。如果想在此处调用popup应该怎么做?
});
};TestClass.prototype.popup = function (value) { alert(value);
}
$(function(){ var testClass = new TestClass();
testClass.init();
}
2 回答
吃鸡游戏
TA贡献1829条经验 获得超7个赞
var TestClass;if (TestClass == undefined) { TestClass = function(){ } } TestClass.prototype.init = function (options) { var self = this; $(".alert_click").click(function(){ self.popup("test");//访问闭包里的this //这样的代码会提示popup未定义。如果想在此处调用popup应该怎么做? }); }; TestClass.prototype.popup = function (value) { alert(value); } $(function(){ var testClass = new TestClass(); testClass.init(); });
www说
TA贡献1775条经验 获得超8个赞
var person = {
name: "Alex Russell",
hello: function() { console.log(this.name + " says hello world"); }
}
$("#some-div").click(person.hello.bind(person));
// when the div is clicked, "Alex Russell says hello world" is printed
添加回答
举报
0/150
提交
取消