-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextend.js
104 lines (77 loc) · 1.6 KB
/
extend.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var extend = function(protoProps) {
var parent = this;
var child = function() { return parent.apply(this, arguments) };
var Surrogate = function() { this.constructor = child; };
Surrogate.prototype = parent.prototype;
child.prototype = new Surrogate;
_.extend(child.prototype, protoProps);
return child;
};
var Foo = function() {
alert("ABC");
};
_.extend(Foo.prototype, {
set: function() {
alert("Bar");
}
});
console.log(Foo.prototype.set);
Foo.extend = extend;
var Class = {
define: function(protoProps) {
var child = function() {};
child.prototype = protoProps;
child.extend = function(protoProps) {
var Proxy = function() {};
Proxy.prototype = this.prototype;
return Class.define(_.extend(new Proxy(), protoProps));
}
return child;
}
};
var Test = Class.define({
constructor: function() {
alert("Construcing a test or test subclass");
},
met: function() {
alert(this.abc);
}
});
var Asdf = Test.extend({
met: function() {
this.foo();
Test.prototype.met.apply(this, arguments);
},
foo: function() {
alert("I'm a foo!");
}
});
var tst = new Test();
tst.abc = "This is a tst";
tst.met();
var bla = new Asdf();
bla.abc = "dspfkdsopfksopdfko";
bla.met();
var Qwer = Asdf.extend({
met: function() {
Asdf.prototype.met.apply(this, arguments);
alert("Lowdash");
}
});
var os = new Qwer();
os.abc = "i'm a qwer";
os.met();
var Super = {
foo: function() {
this.bar();
},
bar: function() {
alert("bar" + this.name);
}
};
function Person() {
}
Person.prototype = Super;
var benjamin = new Person();
benjamin.name = "Benjamin";
benjamin.foo();