-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathworkbench.js
More file actions
121 lines (111 loc) · 2.49 KB
/
workbench.js
File metadata and controls
121 lines (111 loc) · 2.49 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* Created by godsong on 15-9-28.
*/
var Class=require('./class');
var Impl1= Class({
impl1:function(){
}
});
var Impl2= Class({
impl2:function(){
}
});
var A = Class({
//Extends:Impl1,
constructor : function(a) {
//console.log('class A construct with params:', [].join.call(arguments, ','));
this.prop_A = a;
this.prop = 'A';
},
funcA : function() {
console.log('call funcA:', this.prop_A);
},
func : function() {
console.log('call func at[class A] with the private prop:', this.prop)
}
});
function f(){
}
var B = Class({
Extends : A,
constructor : function(b) {
this.Super(2);
// console.log('class B construct with params:', [].join.call(arguments, ','));
this.prop_B = b;
this.prop = 'B';
},
funcB : function() {
},
funcX : function() {
this.Super.funcA();
},
func : function() {
console.log('call func at[class B] with the private prop:', this.prop)
this.Super.func();
}
},true);
B.addAspect({
'after@funcB':function(){
return 123;
}
});
B.mixin({
init:function(){
//console.log('init mixin',this);
},
newFunc:function(){
this.Super.funcA();
}
});
function AA(a){
this.__proto__=_initProto(AA.prototype,{});
this.prop_A = a;
this.prop = 'A';
}
AA.prototype={
funcA : function() {
console.log('call funcA:', this.prop_A);
},
func : function() {
console.log('call func at[class A] with the private prop:', this.prop)
}
};
function _initProto(obj, parent) {
var newObj = {};
for(var key in obj) {
if(obj.hasOwnProperty(key)) {
newObj[key] = obj[key];
}
}
newObj['__proto__'] = parent;
return newObj;
}
function BB(b){
this.Super=new AA(2);
this.__proto__=_initProto(BB.prototype,this.Super);
this.prop_B = b;
this.prop = 'B';
}
BB.prototype={
funcB : function() {
console.log('call funcB:', this.prop_B);
console.log('prop_A:', this.prop_A);
},
funcX : function() {
this.Super.funcA();
},
func : function() {
console.log('call func at[class B] with the private prop:', this.prop)
this.Super.func();
}
};
console.time(2);
for(i=0;i<100000;i++){
new BB();
}
console.timeEnd(2);
console.time(1);
for(var i=0;i<100000;i++){
var b=new B();
}
console.timeEnd(1);