Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Created May 21, 2012 13:42
Show Gist options
  • Save mxriverlynn/2762389 to your computer and use it in GitHub Desktop.
Save mxriverlynn/2762389 to your computer and use it in GitHub Desktop.
$(function(){...}) vs (function($){...})($)
(function($) {
// Backbone code in here
})(jQuery);
$(function(){
// Backbone code in here
});
// Define "MyApp" as a revealing module
MyApp = (function(Backbone, $){
var View = Backbone.View.extend({
// do stuff here
});
return {
init: function(){
var view = new View();
$("#some-div").html(view.render().el);
}
};
})(Backbone, jQuery);
// Run "MyApp" in DOMReady
$(function(){
MyApp.init();
});
@menacestudio
Copy link

I usually do this which might be an overkill.

(function($){
    $(function(){
         // code here...
    });
})(jQuery);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment