Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 76f3586

Browse files
committed
[backbone] backbone proposal
1 parent b74ba8b commit 76f3586

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

README.md

+86
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
1. [Constructors](#constructors)
2626
1. [Modules](#modules)
2727
1. [jQuery](#jquery)
28+
1. [Backbone](#backbone)
2829
1. [ES5 Compatability](#es5)
2930
1. [Testing](#testing)
3031
1. [Performance](#performance)
@@ -1261,6 +1262,91 @@
12611262
**[[⬆]](#TOC)**
12621263

12631264

1265+
## <a name='backbone'>Backbone</a>
1266+
1267+
- Folder structure guidelines (from Rails 3 project root)
1268+
1269+
```
1270+
app/
1271+
└─┬ assets/
1272+
└─┬ apps/
1273+
├── myCoolApp/
1274+
├── anotherCoolApp/
1275+
├── theCoolestApp/
1276+
└─┬ app/
1277+
├─┬ views/
1278+
│ ├── ListItemView.js
1279+
│ └── ListView.js
1280+
├── models/
1281+
├── collections/
1282+
├── routers/
1283+
└── index.js
1284+
config/
1285+
db/
1286+
lib/
1287+
...
1288+
```
1289+
1290+
- The entry point for any Backbone app should be in the `index.js` file found in the root of the application's directory.
1291+
- Generally, it should follow the following structure:
1292+
1293+
```javascript
1294+
// app/assets/apps/app/index.js
1295+
!function($, Backbone) {
1296+
1297+
var app = {
1298+
init: function() {
1299+
// application specific init code goes here
1300+
app.router = new app.Routers.ApplicationRouter();
1301+
Backbone.history.start();
1302+
},
1303+
Views: {},
1304+
Models: {},
1305+
Collections: {},
1306+
Routers: {},
1307+
Helpers: {}
1308+
};
1309+
1310+
$(function(){
1311+
// document ready
1312+
app.init();
1313+
})();
1314+
1315+
}(jQuery, Backbone);
1316+
```
1317+
1318+
- Classes live in the `app` (or app name) object under the corresponding Backbone type (Models, Collections, Views, Routers) with PascalCase
1319+
1320+
```javascript
1321+
// bad
1322+
ListItemView = Backbone.View.extend();
1323+
1324+
// bad
1325+
app.ListItemView = Backbone.View.extend();
1326+
1327+
// good
1328+
app.Views.ListItemView = Backbone.View.extend();
1329+
1330+
// bad
1331+
app.Views.ApplicationRouter = Backbone.Router.extend();
1332+
1333+
// good
1334+
app.Routers.ApplicationRouter = Backbone.Router.extend();
1335+
```
1336+
1337+
- Instances live directly under the `app` object with camelCase
1338+
1339+
```javascript
1340+
// bad
1341+
app.Views.messagesView = new app.Views.ListView();
1342+
1343+
// good
1344+
app.messagesView = new app.Views.ListView();
1345+
```
1346+
1347+
**[[⬆]](#TOC)**
1348+
1349+
12641350
## <a name='es5'>ECMAScript 5 Compatability</a>
12651351
12661352
- Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/)

0 commit comments

Comments
 (0)