Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
$(function(){...}) vs (function($){...})($)
(function($) {
// Backbone code in here
// 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();
})(Backbone, jQuery);
// Run "MyApp" in DOMReady

I've often used the pattern:

jQuery(function($) {
  // Safely use $ here

derickbailey commented May 21, 2012

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

I usually do this which might be an overkill.

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