In Knockout.js, I create an observable array to push models onto:
function Room(data) { this.name = ko.observable(data.name); } function RoomViewModel() { var self = this; self.rooms = ko.observableArray([]); self.newRoomText = ko.observable(); self.addRoom = function() { self.rooms.push(new Room({ name: this.newRoomText() })); self.newRoomText(""); $("#modal").dialog("close"); }.bind(self); }
In Backbone.js, I would create a collection to store my models:
var Book = Backbone.Model.extend(); var Books = new Backbone.Collection([ {name: "Abe Lincoln - Vampire Hunter"} {name: "Pride and Prejudice and Zombies"} ]);
How different are these 2 structures from each other?
What exactly is going on behind the scenes to make these data structures different from the standard Javascript array?
source share