javascript - jQuery plugin tutorial explanation -
i'm following jquery plugins/authoring tutorial, , couldn't figure out arguments
on lines 16 , 18 mean. missing fundamental?
(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 + ' not exist on jquery.tooltip' ); } }; })( jquery );
thank you.
arguments
array-like object contains parameters passed function, including parameters didn't supply variable name for.
it array-like, not array. not contain of array methods, such slice, why have use array.prototype.slice.call(arguments,...)
or [].slice.call(arguments,...)
rather using arguments.slice(...)
Comments
Post a Comment