UNPKG

2.62 kBJavaScriptView Raw
1module.exports = function() {
2 if (!Object.create) {
3 Object.create = function(proto, props) {
4 if (typeof props !== "undefined") {
5 throw "The multiple-argument version of Object.create is not provided by this browser and cannot be shimmed.";
6 }
7 function ctor() { }
8 ctor.prototype = proto;
9 return new ctor();
10 };
11 }
12
13
14 // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
15 if (!Object.keys) {
16 Object.keys = (function () {
17 'use strict';
18 var hasOwnProperty = Object.prototype.hasOwnProperty,
19 hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
20 dontEnums = [
21 'toString',
22 'toLocaleString',
23 'valueOf',
24 'hasOwnProperty',
25 'isPrototypeOf',
26 'propertyIsEnumerable',
27 'constructor'
28 ],
29 dontEnumsLength = dontEnums.length;
30
31 return function (obj) {
32 if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
33 throw new TypeError('Object.keys called on non-object');
34 }
35
36 var result = [], prop, i;
37
38 for (prop in obj) {
39 if (hasOwnProperty.call(obj, prop)) {
40 result.push(prop);
41 }
42 }
43
44 if (hasDontEnumBug) {
45 for (i = 0; i < dontEnumsLength; i++) {
46 if (hasOwnProperty.call(obj, dontEnums[i])) {
47 result.push(dontEnums[i]);
48 }
49 }
50 }
51 return result;
52 };
53 }());
54 }
55
56 // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/lastIndexOf
57 if (!Array.prototype.lastIndexOf) {
58 Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/) {
59 'use strict';
60
61 if (this === void 0 || this === null) {
62 throw new TypeError();
63 }
64
65 var n, k,
66 t = Object(this),
67 len = t.length >>> 0;
68 if (len === 0) {
69 return -1;
70 }
71
72 n = len - 1;
73 if (arguments.length > 1) {
74 n = Number(arguments[1]);
75 if (n != n) {
76 n = 0;
77 }
78 else if (n !== 0 && n != (1 / 0) && n != -(1 / 0)) {
79 n = (n > 0 || -1) * Math.floor(Math.abs(n));
80 }
81 }
82
83 for (k = n >= 0 ? Math.min(n, len - 1) : len - Math.abs(n); k >= 0; k--) {
84 if (k in t && t[k] === searchElement) {
85 return k;
86 }
87 }
88 return -1;
89 };
90 }
91}();
92
93if (window.NodeList && !NodeList.prototype.forEach) {
94 NodeList.prototype.forEach = Array.prototype.forEach;
95}
\No newline at end of file