gpt4 book ai didi

javascript - jQuery 插件调用内部函数

转载 作者:行者123 更新时间:2023-11-30 09:06:43 25 4
gpt4 key购买 nike

我想在内部调用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com