-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
28 lines (23 loc) · 832 Bytes
/
model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
Class for a model - holds some information which a view can then display.
Note that a model might not hold all necessary information when it's used -
you might have to wait for communication over the network, for example.
*/
function model() {
observable.call(this);
}
model.prototype = {
/*
All changes to the model should go through this function.
changes should be an object where properties match properties of this model,
and their values are new values to set the model properties to.
For example, passing {a: 1, b: 2} would essentially do model.a=1 and model.b=2 .
modelChange event is fired with proposed changes before actually changing the model.
*/
change: function(changes) {
this.event("modelChange", this, changes);
for(var i in changes)
this[i] = changes[i];
}
}
extend(model, observable);