failsafe jquery code

The notion is related to when creating plugins, when you can’t for example be sure that $ is an alias for the jQuery object. The failsafe way is to either exclusively use jQuery directly, or wrap it in a closure if you want to be able to use $in your plugin code:

(function($){
  // here code can always use $ as n alias for jQuery, regardless if the user
  // has repointed $ to something else.
})(jQuery);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s