Skip to content

@derickbailey /1.js
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
$(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();
});
@tbranyen

I've often used the pattern:

jQuery(function($) {
  // Safely use $ here
});
@derickbailey

nice - didn't know jQuery passed itself in as a reference like that.

@menacestudio

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
Something went wrong with that request. Please try again.