/ Published in: jQuery

IIFE - Immediately Invoked Function Expression.
http://gregfranko.com/jquery-best-practices/#/7
http://gregfranko.com/jquery-best-practices/#/8
http://gregfranko.com/jquery-best-practices/#/7
http://gregfranko.com/jquery-best-practices/#/8
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// IIFE - Immediately Invoked Function Expression (function($, window, document) { // The $ is now locally scoped // Listen for the jQuery ready event on the document $(function() { // The DOM is ready! }); // The rest of the code goes here! }(window.jQuery, window, document)); // The global jQuery object is passed as a parameter //-------------------------------------------------- // IIFE - Immediately Invoked Function Expression (function(yourcode) { // The global jQuery object is passed as a parameter yourcode(window.jQuery, window, document); }(function($, window, document) { // The $ is now locally scoped // Listen for the jQuery ready event on the document $(function() { // The DOM is ready! }); console.log('The DOM may not be ready'); // The rest of code goes here! }));
Comments
