-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (79 loc) · 2.27 KB
/
index.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
'use strict';
exports.fn = function(fn,throwable,ctx) {
throwable = ('undefined' == typeof throwable ? true:throwable);
return function(){
var _this = ctx ||this;
var args = Array.prototype.slice.call(arguments);
return function(done){
args[args.length] = function(){ //the callback
var results = Array.prototype.slice.call(arguments);
if(!throwable){
results.splice(0,0,null);
}
done.apply(null ,results);
};
fn.apply(_this,args);
};
};
};
exports.object = function(object,throwable,methods,prefix,ctx) {
throwable = ('undefined' == typeof throwable ? true:throwable);
prefix = prefix || '$';
ctx = ctx || object;
Object.keys(object).forEach(function(i){
var target ;
try{
target = object[i]; //accessing property in prototype will trigger a error!
}catch(e){
return ;
}
if('function' != typeof target || target && target.constructor && 'GeneratorFunction' == target.constructor.name ){
return;
}
if(methods && -1==methods.indexOf(i)){
return;
}
object[prefix+i] = exports.fn(target,throwable , ctx);
});
};
exports.class = function(constructor,throwable,methods,prefix) {
throwable = ('undefined' == typeof throwable ? true:throwable);
function _class(prototypeObject,throwable,methods,prefix){
if(!prototypeObject){
return;
}else{
// cofy parent class
_class(Object.getPrototypeOf(prototypeObject),throwable,methods,prefix);
}
prefix = prefix || '$';
Object.keys(prototypeObject).forEach(function(i){
var target ;
try{
target = prototypeObject[i]; //accessing property in prototype will trigger a error!
}catch(e){
return ;
}
if('function' != typeof target || target && target.constructor && 'GeneratorFunction' == target.constructor.name ){
return;
}
if(methods && -1==methods.indexOf(i)){
return;
}
prototypeObject[prefix+i] = function(){
var _this = this;
var args = Array.prototype.slice.call(arguments);
return function(done){
args[args.length] = function(){ //the callback
var results = Array.prototype.slice.call(arguments);
if(!throwable){
results.splice(0,0,null);
}
done.apply(null ,results);
};
prototypeObject[i].apply(_this,args);
};
};
});
}
_class(constructor.prototype,throwable,methods,prefix);
};