javascript - jQuery javascript : Array.prototype.slice.call的含义

标签 javascript jquery arrays prototype

我想问一下下面代码的含义:

$.fn.datepick = function(options) {
    var otherArgs = Array.prototype.slice.call(arguments, 1);

这些是 jQuery 插件的第 2036 - 2037 行 文件“jquery.datepick.js”来自

http://keith-wood.name/datepick.html

最佳答案

完整的代码如下所示:

/* Attach the datepicker functionality to a jQuery selection.
   @param  options  (object) the new settings to use for these instances (optional) or
                    (string) the command to run (optional)
   @return  (jQuery) for chaining further calls or
            (any) getter value */
$.fn.datepick = function(options) {
    var otherArgs = Array.prototype.slice.call(arguments, 1);
    if (isNotChained(options, otherArgs)) {
        return plugin['_' + options + 'Plugin'].apply(plugin, [this[0]].concat(otherArgs));
    }
    return this.each(function() {
        if (typeof options == 'string') {
            if (!plugin['_' + options + 'Plugin']) {
                throw 'Unknown command: ' + options;
            }
            plugin['_' + options + 'Plugin'].apply(plugin, [this].concat(otherArgs));
        }
        else {
            plugin._attachPlugin(this, options || {});
        }
    });
};

关于javascript - jQuery javascript : Array.prototype.slice.call的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19978857/

相关文章:

javascript - 为什么这些商品无法添加到购物车?

Javascript IE6 getElementsByTagName 不工作

javascript - Ajax 调用后数据属性长度检查

arrays - 如何解决 Java heap space Exception for ArrayList Size?

java使每一行成为数组或列表

javascript - node js无法处理sns事件消息内容

javascript - 从虚拟字符串中获取数字

jquery validate 不适用于多种表单

javascript - 在 ui.bootstrap Angular Modal 中使用 JQuery $.each 运算符将 CSS 应用于每个元素

javascript - 如何获取多个复选框值并分配给隐藏字段