I have seen several ways to do this, but I can never understand what is “right”.
Jeffrey Way of NetTuts + and Addy Osmani will instantiate the "main" look of the application to launch their applications.
require(['views/app'], function(AppView) {
new AppView();
});
Railscasts Ryancasts starts his application by creating an instance of a router that then processes the following requests:
window.App =
Models: {}
Collections: {}
Views: {}
Routers: {}
init: ->
new App.Router()
Backbone.history.start()
}
}
$(document).ready ->
App.init()
Is there a difference between the two ways to download the application?
, App, , ,... CoffeeScript, , - , . , RequireJS:
require(['jquery', 'backbone', 'router'], function ($, Backbone, Router) {
window.App = {
Models: {},
Collections: {},
Views: {},
Aggregator: _.extend({}, Backbone.Events),
Hook: $('#application'),
Router: Router,
init: function() {
new App.Router();
Backbone.history.start();
}
}
$(document)ready(function() {
App.init();
});
});
, loginView :
define(['backbone', 'loginView'], function(Backbone, LoginView) {
var Router = Backbone.Router.extend({
routes: {
'': 'index'
},
index: function() {
var loginView = new LoginView();
}
});
return Router;
});
loginView:
define(['backbone'], function(Backbone) {
var LoginView = Backbone.View.extend({
});
return LoginView;
});
, - :
App.Views.LoginView = Backbone.View.extend({});
, , coffeescript:
class App.Views.LoginView extends Backbone.View
"" LoginView initialize, main.js, , - App.Views, App. undefined. , - ?