-
-
Save mxriverlynn/2762389 to your computer and use it in GitHub Desktop.
$(function(){...}) vs (function($){...})($)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
// Backbone code in here | |
})(jQuery); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
// Backbone code in here | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
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
nice - didn't know jQuery passed itself in as a reference like that.