-
Notifications
You must be signed in to change notification settings - Fork 27
/
contra.shim.js
77 lines (77 loc) · 2.21 KB
/
contra.shim.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
(function (Object, Array) {
'use strict';
if (!Array.prototype.forEach) {
Array.prototype.forEach = function (fn, ctx) {
if (this === void 0 || this === null || typeof fn !== 'function') {
throw new TypeError();
}
var t = this;
var len = t.length;
for (var i = 0; i < len; i++) {
if (i in t) { fn.call(ctx, t[i], i, t); }
}
};
}
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (what, start) {
if (this === undefined || this === null) {
throw new TypeError();
}
var length = this.length;
start = +start || 0;
if (Math.abs(start) === Infinity) {
start = 0;
} else if (start < 0) {
start += length;
if (start < 0) { start = 0; }
}
for (; start < length; start++) {
if (this[start] === what) {
return start;
}
}
return -1;
};
}
if (!Array.prototype.filter) {
Array.prototype.filter = function (fn, ctx) {
var f = [];
this.forEach(function (v, i, t) {
if (fn.call(ctx, v, i, t)) { f.push(v); }
}, ctx);
return f;
};
}
if (!Function.prototype.bind) {
Function.prototype.bind = function (context) {
if (typeof this !== 'function') {
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
}
var curried = Array.prototype.slice.call(arguments, 1);
var original = this;
var NoOp = function () {};
var bound = function () {
var ctx = this instanceof NoOp && context ? this : context;
var args = curried.concat(Array.prototype.slice.call(arguments));
return original.apply(ctx, args);
};
NoOp.prototype = this.prototype;
bound.prototype = new NoOp();
return bound;
};
}
if (!Object.keys) {
Object.keys = function (o) {
var keys = [];
for (var k in o) {
if (o.hasOwnProperty(k)) {
keys.push(k);
}
}
return keys;
};
}
if (Object.defineProperty) { // test for IE8 partial implementation
try { Object.defineProperty({}, 'x', {}); } catch (e) { Object.definePropertyPartial = true; }
}
})(Object, Array);