javascript - 为具有 1 个变量/对象的函数提供多个参数

标签 javascript

作为一个例子,我以 jQuery 动画函数为例: 正常情况下它的工作原理是这样的:

$("#div1").animate({
                width: '300px',
            }, 1000, function() {
                console.log("animate 1 done");
            });

我想要这样的:

animateConfig = [{
                width: '300px',

            }, 1000, function() {
                console.log("animate1 done");
            }];

startAnimate($("#div1"), animateConfig);

function startAnimate(obj, animateConfig) {
    console.log(animateConfig);
    obj.animate(animateConfig);

}

也是一个 fiddle :http://fiddle.jshell.net/hVXKM/1/

最佳答案

尝试:

obj.animate.apply(obj, animateConfig);

关于javascript - 为具有 1 个变量/对象的函数提供多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18542923/

相关文章:

Javascript 正则表达式 : How to find a string that not ended with a paticular word(not a single letter)?

javascript - 从服务器 Backbone.js 应用程序获取数据

javascript - jQuery 选择器以相反的方式开始

javascript - 在 Mocha 输出中显示测试文件名

javascript - 将差异转换为百分比

javascript - 如何在 SVG 中获取有效的动态 javascript 引用

javascript - history.replaceState 不适用于 firefox v56+

javascript - 如何在移动页面末尾自动显示 "load more"

javascript - 你可以在 Web Workers 之间共享 WebAssembly 内存吗?

javascript - 如何对 PDF 文件中的文本搜索和替换进行编程