我想在内部调用 removeSomething()(见第 9 行):
JS 代码是:
(function($){
$.fn.extend({
Engine: function(options) {
var defaults = {
...
};
var options = $.extend(defaults, options);
removeSomething();
//-----------------------------------------------------------------------
//Public Functions ------------------------------------------------------
//-----------------------------------------------------------------------
this.removeSomething = function() {
...
};
}
});
})(jQuery);
但是如果我调用 removeSomething 控制台输出 removeSomething 不是一个函数,我该如何调用这个函数呢?该功能应在内部和外部可用。
感谢您的帮助!
最佳答案
当使用 var
或其他 = function() {...
语法声明时,函数需要在使用之前定义它,并调用了它的定义,在这种情况下:
this.removeSomething = function() {
...
};
//*then*
this.removeSomething();
关于javascript - jQuery 插件调用内部函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4570189/