我不确定我需要使用什么标题或我需要调用我要做的事情,这就是问题
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/