1
我想學習jquery插件,在這個過程中我想先了解一些jquery插件。我已經閱讀了幾個插件,並在插件的開始部分遇到了幾個常見的代碼。是init.apply和方法[方法] .apply JavaScript行默認
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.jModalbox');
}
任何機構可以告訴我,
- 是像,我們要按照這個建設我已經觀察到的插件
當控制檯將不以
返回方法[方法] .apply(this,Array.prototype.slice.call(arguments,1));
那麼爲什麼我們需要if部分。
- 爲什麼調用該方法適用於INIT,我的意思是 爲什麼調用,如:
methods.init.apply(this, arguments);
爲什麼不喜歡這樣的:methods.init(arguments);
- 我所遇到的閱讀apply(),但並不清楚。請任何機構解釋