【问题标题】:the meaning of jQuery javascript: Array.prototype.slice.calljQuery javascript的含义:Array.prototype.slice.call
【发布时间】:2013-11-27 12:49:39
【问题描述】:

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

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

这些是 jQuery 插件的第 2036 - 2037 行 来自

的文件'jquery.datepick.js'

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

【问题讨论】:

标签: javascript jquery arrays prototype


【解决方案1】:

完整的代码如下所示:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-26
    • 2013-07-09
    • 1970-01-01
    • 2015-10-16
    • 2011-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多