2013-05-02 57 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(...)