Looking into the todomvc backbone codes example. The structure in the js/ fold:
├── app.js
├── collections
│?? └── todos.js
├── models
│?? └── todo.js
├── routers
│?? └── router.js
└── views
├── app-view.js
└── todo-view.js
app.js
var app = app || {};
$(function () {
'use strict';
// kick things off by creating the `App`
new app.AppView();
});
collections/todos.js
var app = app || {};
(function () {
'use strict';
var Todos = Backbone.Collection.extend({
model: app.Todo,
app.todos = new Todos();
})();
models/todo.js
var app = app || {};
(function () {
'use strict';
app.Todo = Backbone.Model.extend({
});
})();
views/app-view.js
var app = app || {};
(function ($) {
'use strict';
app.AppView = Backbone.View.extend({
})(jQuery);
I have two questions:
why
var app = app || {}
in each file?What are the differences between
$(function(){})
,(function(){})()
, and(function($))(jQuery)
?