I’m writing a plugin, and I got the basic setup from the jQuery plugin authoring tutorial:
(function( $ ){
var methods = {
init : function( items ) {
/* do stuff */
},
reset : function( name ) {
// here I need the var items from init
}
};
$.fn.myplugin = 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 );
How can I get in the method reset the variable items from init?
Thanks and regards, alex
You could store them in the smallest common scope, e.g. the
methodsobject: