本文介绍了变量范围:this.remove不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
this.remove()不是函数。为什么?
this.remove() is not a function. How come?
var vehicle = function () {
return {
init: function () {
jQuery('.vehicle-year-profile .options .delete').bind('click', function (e) {
e.preventDefault();
this.remove();
});
},
remove: function () {
alert('test');
}
}
}();
jQuery().ready(vehicle.init);
对此感到困惑。我正在尝试调用自己的删除功能。这只是一个管理我页面上的车辆的类。这是它的开始,它将具有比init / remove更多的功能。
Sorry for the confusion. I'm trying to call my own "remove" function. This is simply a class to manage vehicles on my page. This is the beginning of it and it will have a lot more functions than just init/remove.
推荐答案
既然你说过你'重新尝试调用你自己的删除
函数,这里是如何做到的:
Since you said you're trying to call your own remove
function, here's how to do it:
var vehicle = (function () {
return {
init: function () {
var that = this; // step one
jQuery('.vehicle-year-profile .options .delete').bind('click', function (e) {
e.preventDefault();
that.remove();
});
},
remove: function () {
alert('test');
}
}
}()); // step zero - wrap the immediate invocation in parens
jQuery(function () {
vehicle.init(); // step two
);
这篇关于变量范围:this.remove不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!