我创建了一些小部件工厂,我想在公共方法中访问它的选项或方法,但它返回错误“142 Uncaught TypeError: Object has no method”或“无法读取属性”。如何正确访问?
这是示例:
function($){
$.widget("demo.myWidget",{
options:{
myVar:0
},
_create:function(){
//this line work in here
alert(this.options.myVar);
},
calledFunction : function(){
alert(this._getVar());
},
pubFunction : function(){
setInterval(this.calledFunction, 1000);
},
_getVar : function(){
return this.options.myVar;
}
});
}(jQuery));
$(document).ready(function(){
$("selector").myWidget();
$("selector").myWidget("pubFunction");
});
如果我访问 _create 方法中的选项,它工作正常。之前谢谢你。