/
abstract-mapper.js
44 lines (40 loc) · 1.12 KB
/
abstract-mapper.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
(function() {
var AbstractMapper;
this.AbstractMapper = AbstractMapper = (function() {
function AbstractMapper(_map) {
var handler, i, len, map, mapper;
if (_map == null) {
_map = [];
}
map = [];
for (i = 0, len = _map.length; i < len; i++) {
handler = _map[i];
switch (false) {
case typeof handler !== 'function':
map.push(handler);
break;
case !(handler instanceof Array):
mapper = new this.constructor(handler);
map.push((function(mapper) {
return function() {
return mapper.apply(this, arguments);
};
})(mapper));
}
}
return function() {
var context, j, len1, result;
for (j = 0, len1 = map.length; j < len1; j++) {
handler = map[j];
if (!context) {
context = result = handler.apply(this, arguments);
} else {
result = handler.apply(context, arguments);
}
}
return result;
};
}
return AbstractMapper;
})();
}).call(this);