I created a plugin but want to be sure about what I do with "local" functions.
Here is schematically what I did :
(function($) {
var methods = {
init : function( options ) {
// CODE ...
// Call of a local function
_test( this );
// CODE .....
},
destroy : function( ) {
// CODE .....
_test( this );
// CODE .....
}
};
function _test( container ) {
// My code : example :
$(container).append("<div id='myplugin'></div>");
}
$.fn.myplugin = function( method ) {
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.myplugin' );
}
};
})(jQuery);
As you can see, I don't directly insert the code in the methods functions but in other _functions. Is the _functions can be considered as local or private function of the plugin ? I don't success to call them outside of the plugin, so it seems for me they can be considered private functions...
Do I have always to put my code in the function in the methods object directly ? How to declare functions which will be used in several methods ?
And what about the namespace ? Don't really understand.
Thanks !