JSFiddle - React, Tailwind, and code Playground
HTML
<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Learning About Backbone.js Collection</title>
</head>
<body>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/backbone/backbone-min.js"></script>
</body>
</html>
JavaScript
var Person = Backbone.Model.extend({
initialize: function() {
console.log('Person is initialized.');
},
defaults: {
name: 'undefined',
age: 'undefined'
}
});
var People = Backbone.Collection.extend({
initialize: function() {
console.log("People Collection is initialized");
},
model: Person
});
var person = new Person({name:"Joe"});
var people = new People(person);
people.add([{name:"Bob"}, {name:"Jim"}]);
console.log(people.toJSON());