Baseline boot application

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. , - ?

+5
1

:

App.Views.LoginView = Backbone.View.extend({});

:

class App.Views.LoginView extends Backbone.View

coffeescript, coffee js:

var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

App.Views.LoginView = (function(_super) {

  __extends(LoginView, _super);

  function LoginView() {
    return LoginView.__super__.constructor.apply(this, arguments);
  }

return LoginView;

})(Backbone.View);

todomvc backbone-require setup.

coffeescript todo, , , , , ..

0

All Articles