2013-05-02 55 views
0

我正在关注的JQuery Plugins/Authoring教程,并行和意味着无法弄清楚什么arguments。我错过了一些真正的根本吗?jQuery插件教程解释

(function($){ 

var methods = { 
    init : function(options) { 
    // ... 
    }, 
    show : function() { 
    // ... 
}; 

$.fn.tooltip = function(method) { 

    // Method calling logic 
    if (methods[method]) { 
     return methods[ method ]. 
      apply(this, Array.prototype.slice.call(arguments, 1)); 
    } else if (typeof method === 'object' || ! method) { 
     return methods.init.apply(this, arguments); 
    } else { 
     $.error('Method ' + method + ' does not exist on jQuery.tooltip'); 
    }  

}; 

})(jQuery); 

谢谢。

+0

btw,是否有无论如何显示自动代码行号?谢谢。 – xcorat 2013-05-02 14:52:15

+1

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments – jbabey 2013-05-02 14:52:51

+1

给您的评论,没有。使用线内评论 – 2013-05-02 14:52:57

回答

1

arguments阵列状对象包含被传递到该函数,包括,你没有用于提供一个可变名称参数的参数。它是数组式的,但不是数组。它不包含任何数组方法,如切片,这就是为什么你必须使用Array.prototype.slice.call(arguments,...)[].slice.call(arguments,...)而不仅仅是使用arguments.slice(...)