addyosmani/backbone-fundamentals — Issue #60: Backbone(underscore) issue with Require.js
Author: bardu
Created: 2012-01-29 20:44:33+00:00
State: open

Since I'm using node.js on the server side I prefer the "simplified CommonJS wrapping" to define modules like this:

define(function(require) {
var $ = require('jquery'),
_ = require('underscore'),
Backbone = require('backbone');

// require jquery plugins
require('jqueryui');
require('jquery-plugins/jquery.gritter');
require('jquery-plugins/same-height');

return Backbone.View.extend({ ... });

});

However, Backbone.View.extend() always raised the error "Backbone is null".

Google lead me to this thread:

https://github.com/documentcloud/underscore/commit/0d4b1247c45083c695cab4242c084a97aa600221

and wrapping Backbone into an AMD module like this:

define(['jquery', 'underscore'], function($, _){
// paste Backbone.js source code here
return Backbone;
});

fixed the issue.

I think this is worth noting it in your book.

Stephan