-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
43 lines (37 loc) · 1.17 KB
/
util.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
var util = (function () {
return {
/**
* inheritPrototype() and inherits() are almost the same, except for "super_" in subType,
* inherits() is RECOMMENDED!
*
* inherits util Usage example:
*
* function SuperType(name){
* this.name=name;
* }
* SuperType.prototype.sayName=function(){console.log(this.name)}
*
* function SubType(name,age){
* SuperType.call(this,name); //[***]
* this.age=age;
* }
* inheritPrototype(SubType,SuperType);
*/
inheritPrototype: function (subType, superType) {
var prototype = Object.create(superType.prototype);
prototype.constructor = subType;
subType.prototype = prototype;
},
inherits: function (ctor, superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
};
}());