-
Notifications
You must be signed in to change notification settings - Fork 1
/
todo_mvc.js
76 lines (66 loc) · 1.51 KB
/
todo_mvc.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
;(function(global, j, _) {
function _extends(klass, subklass, methods) {
// copy methods from super
for(var p in klass.prototype) {
if(klass.prototype.hasOwnProperty(p)) {
subklass.prototype[p] = klass.prototype[p];
}
}
// copy methods
for(var p in methods) {
subklass.prototype[p] = methods[p];
}
// set super class
subklass.prototype._super = klass;
}
function Events() {
this.events = [];
}
Events.prototype = {
addEvent: function(name, f) {
if(this.events[name] == null) {
this.events[name] = [];
}
this.events[name].push(f);
},
fireEvent: function(name) {
var args = arguments;
_(this.events[name]).each(function(f) {
f(Array.prototype.slice.call(args, 1));
});
}
}
function Collection() {
Events.call(this);
this.items = [];
};
_extends(Events, Collection, {
add: function(item) {
this.items.push(item);
},
update: function(id, item) {
this.item[id] = item;
},
remove: function(id) {
this.items.splice(id, 1);
}
});
function TodoList(title) {
Collection.call(this);
this.title = title;
}
_extends(Collection, TodoList, {
add: function(x) {
this._super.prototype.add.call(this, x);
this.foo = "bar";
}
});
function init() {
console.log("init");
}
j(document).ready(init);
_.extend(global, {
Collection: Collection,
TodoList: TodoList
});
})(this, jQuery, Underscore);