我不确定如何在模块化(RequireJs)Backbone环境中使用命名空间。如何在Requirebone中使用Backbone中的命名空间
我已经想了一下它如何可能看起来像但我完全不确定这是否是正确的方式。
app.js(过得去main.js执行)
define('App', ['underscore', 'backbone', 'Router'], function(_, Backbone, Router){
function initialize(){
var app = {}; // app is the global namespace variable, every module exists in app
app.router = new Router(); // router gets registered
Backbone.history.start();
}
return { initialize: initialize }
});
messages.js
define('MessageModel', ['underscore', 'backbone', 'App'], function(_, Backbone, App){
App.Message.Model; // registering the Message namespace with the Model class
App.Message.Model = Backbone.Model.extend({
// the backbone stuff
});
return App;
});
这是正确的做法或完全是我的错误的方式(如果是,请纠正我!)
嗨,我查看了代码。这是我目前使用RequireJs的方式,但是我错过了命名空间(总是有另一个变量没有“全局”之一) – 2012-07-08 09:25:10
链接不再工作:(任何想法在哪里检索该资源? – lucke84 2013-01-21 17:35:59
http://addyosmani.github.com/todomvc/dependency-examples/backbone_require/ – 2013-01-21 17:40:02