KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I currently have a working AMD Backbone Model using require.js like so: // models/game.js define(['backbone'], function(Backbone) { var Game = Backbone.Model.extend({ urlRoot : '/games/' , defaults : { name : null } }); return Game; }); The AMD/Backbone organization comes from this tutorial and jrburke's Pull Request for Backbone . I'd like to use the Backbone Model in Node.js too, because sharing Backbone models and collections has worked well in the past when not using AMD and, well, apparently I'm a masochist. So I tried the following (inspired by the Backbone mod): // models/game.js (function(root, factory) { if (typeof exports !== 'undefined') { factory(root, exports, require('backbone')); } else if (typeof define === 'function' && define.amd) { define(['backbone'], function(Backbone, exports) { factory(root, exports, Backbone); }); } }(this, function(root, Game, Backbone) { Game = Backbone.Model.extend({ urlRoot : '/games/' , defaults : { name : null } }); return Game; })); But Game is now undefined when I include it in the browser: // collections/games.js define(['backbone', 'models/game'], function(Backbone, Game) { var Games = Backbone.Collection.extend({ model: Game , initialize: function() { console.log(Game) // Game is undefined var game = new Game({ name: 'game1' }); } }); return Games; }); While I looked at the CommonJS notes , I'm afraid I'm still unclear. How do I use the same Backb
Tags (comma-separated)
Save Edits
Cancel