forked from andyedinborough/RazorJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototypes.js
More file actions
49 lines (43 loc) · 1.28 KB
/
Copy pathprototypes.js
File metadata and controls
49 lines (43 loc) · 1.28 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
function ifNative(func) {
if (func && ~func.toString().indexOf('[native code]'))
return func;
}
var proxy = function (func) {
return function (obj, arg) { return func.apply(obj, [arg]); };
};
var each = proxy(ifNative(Array.prototype.forEach) || function (func, thisObj) {
var l = this.length, j = l, i, scope = thisObj || global;
while (j--) func.apply(scope, [this[(i = l - j - 1)], i]);
});
var map = proxy(ifNative(Array.prototype.map) || function (fn, thisObj) {
var scope = thisObj || global, a = [];
for (var i = 0, j = this.length; i < j; ++i) {
a.push(fn.call(scope, this[i], i, this));
}
return a;
});
var some = proxy(ifNative(Array.prototype.some) || function (fn, thisObj) {
var scope = thisObj || global;
for (var i = 0, j = this.length; i < j; ++i) {
if (fn.call(scope, this[i], i, this)) {
return true;
}
}
return false;
});
//Dear IE8: I hate you.
var specialKeys = ['toString', 'valueOf'];
var objectKeys = ifNative(Object.keys) || function (a) {
var ret = [];
for (var i in a)
if (a.hasOwnProperty(i))
ret.push(i);
each(specialKeys, function (key) {
if (a[key] !== Object.prototype[key])
ret.push(key);
});
return ret;
};
var bind = proxy(Function.prototype.bind || function(func, obj) {
return function(){ return func.apply(obj, arguments); };
});