gpt4 book ai didi

javascript - 如何从另一个函数扩展被调用的回调

转载 作者:行者123 更新时间:2023-12-03 12:27:45 25 4
gpt4 key购买 nike

我不确定我需要使用什么标题或我需要调用我要做的事情,这就是问题

sortable.js中有一段代码

var sortableStuff;

sortableStuff = {

sortableList = $('#mySortable');

init: function(){

sortableList.sortable({

start: function(){

lot of codes here...

},

stop: function() {

another codes here..
}
});
}

}

我想从另一个文件(例如 mysortable.js)扩展启动和停止函数,但仍然从上面的文件运行启动和停止回调。

sortableStuff.sortableList.sortable({
start: function(){
run the code from the start before..

run my new code
}
})

我不是 JavaScript 专家,不知道该怎么称呼我在这里要做的事情,请帮助我。

最佳答案

您的第一个脚本中存在语法错误,将对象文字与变量赋值混合在一起。应该是

var sortableStuff = {
sortableList: $('#mySortable'),
// ^ ^
init: function() {
this.sortableList.sortable({
// ^^^^^ use as a property
start: function(){
// lot of codes here...
},
stop: function() {
// another codes here..
}
});
}
};

现在您可以从外部访问 sortableStuff.sortableList,并且根据您的 sortable 插件的工作方式能够扩展/添加/覆盖回调。

关于javascript - 如何从另一个函数扩展被调用的回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24098671/

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