提交 | 用户 | 时间
|
1ac2bc
|
1 |
// This methods allows the killing of built-in functions, |
懒 |
2 |
// so the shim can take over with that implementation |
|
3 |
var HLP = (function() { |
|
4 |
"use strict"; |
|
5 |
var kill; |
|
6 |
|
|
7 |
kill = function(_class, methods) { |
|
8 |
/*if(!Array.isArray(methods)) |
|
9 |
return;*/ |
|
10 |
if(!_class.originals) |
|
11 |
_class.originals = {}; |
|
12 |
|
|
13 |
for (var i = 0, len = methods.length; i < len; i++) { |
|
14 |
var obj = methods[i]; |
|
15 |
_class.originals[obj] = _class[obj]; |
|
16 |
delete _class[obj]; |
|
17 |
if (obj in _class) { |
|
18 |
// try something more aggressive since V8 at least |
|
19 |
// appears to ignore the delete. |
|
20 |
_class[obj] = null; |
|
21 |
if (_class[obj]) { |
|
22 |
console.log("Couln't overwrite", obj, "of", _class); |
|
23 |
} |
|
24 |
} |
|
25 |
} |
|
26 |
}; |
|
27 |
return { kill: kill }; |
|
28 |
}()); |
|
29 |
|
|
30 |
HLP.kill(Function.prototype, [ |
|
31 |
'bind' |
|
32 |
]); |
|
33 |
|
|
34 |
HLP.kill(Array, [ |
|
35 |
'isArray' |
|
36 |
]); |
|
37 |
|
|
38 |
HLP.kill(String.prototype, [ |
|
39 |
"trim" |
|
40 |
]); |
|
41 |
|
|
42 |
HLP.kill(Object, [ |
|
43 |
'keys' |
|
44 |
]); |
|
45 |
|
|
46 |
HLP.kill(Number.prototype, [ |
|
47 |
'toFixed' |
|
48 |
]); |
|
49 |
|
|
50 |
HLP.kill(Date, [ |
|
51 |
'now', 'parse' |
|
52 |
]); |
|
53 |
|
|
54 |
HLP.kill(Date.prototype, [ |
|
55 |
"toJSON", "toISOString" |
|
56 |
]); |
|
57 |
|
|
58 |
HLP.kill(Array.prototype, [ |
|
59 |
'forEach', 'some', 'every', |
|
60 |
'indexOf', 'lastIndexOf', |
|
61 |
'map', 'filter', |
|
62 |
'reduce', 'reduceRight' |
|
63 |
]); |
|
64 |
|