javascript - jQuery plugin template -


I'm getting this template to build a jQuery plugin

but I do not understand the code, Why declare the plugin as a method of jQuery object, and then we declare the plugin as a method of object $ .fn, why did we do this?

Adding the plugin to $ enables you to write:

  var $ el = $ ("myselector"); $ .myplugin ($ el, {something: "options", second: "one"});  

Writing the plugin in $ .fn enables you to write:

  $ (".myselector"). Myplugin ({some: "options", second: "one"});  

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -