-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
37 lines (37 loc) · 904 Bytes
/
main.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
var bind, main, opts;
bind = function(fn, ob){
return function(){
return fn.apply(ob, arguments);
};
};
main = function(ob, methods, allNames, attachTo){
var len, name, bound;
len = allNames.length + 1;
while (--len) {
name = allNames[len - 1];
bound = bind(methods[name], ob);
attachTo[name] = bound;
}
return attachTo;
};
opts = function(ob, methods){
var attachTo, allNames, userOption;
attachTo = methods;
switch (arguments.length) {
case 2:
allNames = Object.getOwnPropertyNames(methods);
break;
case 3:
userOption = arguments[2];
if (userOption.select || userOption.s) {
allNames = userOption.select;
} else {
allNames = Object.getOwnPropertyNames(methods);
}
if (userOption.addto || userOption.a) {
attachTo = userOption.addto;
}
}
return main(ob, methods, allNames, attachTo);
};
module.exports = opts;