Creating jQuery helper plug-in -
how write jquery helper plug-in can invoke $.myplugin(), opposed $.fn.myplugin()?
with plug-in created in following way, can call $("selector").myplugin() or $.fn.myplugin().
(function( $ ){ $.fn.myplugin = function() { }; })( jquery ); , myplugin() helper function doesn't need this reference. idea?
@andres has provided 1 of possibilities of defining jquery plugin, though it's more usual define plugin using $.extend functionality.
(function($) { // plugin closure var defaults = { ... }; $.extend({ myplugin: function(options) { // when options needed options = $.extend({}, defaults, options); // functionality afterwards } }); })(jquery);
Comments
Post a Comment