Browse Source

解决chrome39兼容

seimin 3 years ago
parent
commit
7cc9e948f5
1 changed files with 57 additions and 3 deletions
  1. 57 3
      src/polyfills.ts

+ 57 - 3
src/polyfills.ts

@@ -13,6 +13,62 @@
13 13
  *
14 14
  * Learn more in https://angular.io/guide/browser-support
15 15
  */
16
+// Array.prototype.includes()兼容问题,2021年7月21日-seimin
17
+if (!Array.prototype.includes) {
18
+  Object.defineProperty(Array.prototype, "includes", {
19
+    value: function (valueToFind, fromIndex) {
20
+      if (this == null) {
21
+        throw new TypeError('"this" is null or not defined');
22
+      }
23
+
24
+      // 1. Let O be ? ToObject(this value).
25
+      var o = Object(this);
26
+
27
+      // 2. Let len be ? ToLength(? Get(O, "length")).
28
+      var len = o.length >>> 0;
29
+
30
+      // 3. If len is 0, return false.
31
+      if (len === 0) {
32
+        return false;
33
+      }
34
+
35
+      // 4. Let n be ? ToInteger(fromIndex).
36
+      //    (If fromIndex is undefined, this step produces the value 0.)
37
+      var n = fromIndex | 0;
38
+
39
+      // 5. If n ≥ 0, then
40
+      //  a. Let k be n.
41
+      // 6. Else n < 0,
42
+      //  a. Let k be len + n.
43
+      //  b. If k < 0, let k be 0.
44
+      var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
45
+
46
+      function sameValueZero(x, y) {
47
+        return (
48
+          x === y ||
49
+          (typeof x === "number" &&
50
+            typeof y === "number" &&
51
+            isNaN(x) &&
52
+            isNaN(y))
53
+        );
54
+      }
55
+
56
+      // 7. Repeat, while k < len
57
+      while (k < len) {
58
+        // a. Let elementK be the result of ? Get(O, ! ToString(k)).
59
+        // b. If SameValueZero(valueToFind, elementK) is true, return true.
60
+        if (sameValueZero(o[k], valueToFind)) {
61
+          return true;
62
+        }
63
+        // c. Increase k by 1.
64
+        k++;
65
+      }
66
+
67
+      // 8. Return false
68
+      return false;
69
+    },
70
+  });
71
+}
16 72
 // (function () {
17 73
 //     Object.setPrototypeOf = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array ? setProtoOf : mixinProperties);
18 74
 
@@ -179,9 +235,7 @@
179 235
  * APPLICATION IMPORTS
180 236
  */
181 237
 
182
-
183
-import 'zone.js/dist/zone';  // Included with Angular CLI.
184
-
238
+import "zone.js/dist/zone"; // Included with Angular CLI.
185 239
 
186 240
 // import 'babel-polyfill';
187 241