a simple boilerplate to build jquery plugins
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
css
js
more
jquery.sb_basic.js
jquery.sb_chain.js
jquery.sb_namespace.js
readme.md
sandbox.html

readme.md

jquery.boilerplate

A boilerplate & sandbox to build & practice jQuery plugins

Best Practices

Writing jQuery plugins allows you to make the most out of the library and abstract your most clever and useful functions out into reusable code that can save you time and make your development even more efficient. Here's a brief summary of the post and what to keep in mind when developing your next jQuery plugin:

  • Always wrap your plugin in (function( $ ){ // plugin goes here })( jQuery );
  • Don't redundantly wrap the this keyword in the immediate scope of your plugin's function
  • Unless you're returning an intrinsic value from your plugin, always have your plugin's function return the this keyword to maintain chainability.
  • Rather than requiring a lengthy amount of arguments, pass your plugin settings in an object literal that can be extended over the plugin's defaults.
  • Don't clutter the jQuery.fn object with more than one namespace per plugin.
  • Always namespace your methods, events and data.
  • jQuery.fn is pronounced jQuery effin'

(used with thanks http://docs.jquery.com/Plugins/Authoring)

Further reading

History

v0.2
- chaining & namespace examples
- demo html

v0.1
- initial