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

时间:2013-11-14 13:25:35

标签: 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

1 个答案:

答案 0 :(得分:0)

完整代码如下所示:

/* 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 || {});
        }
    });
};