1 | exports.enable = function() { |
||
2 | //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes |
||
3 | if (!Array.prototype.includes) { |
||
4 | Object.defineProperty(Array.prototype, 'includes', { |
||
5 | enumerable: false, |
||
6 | value: function(searchElement /*, fromIndex*/ ) { |
||
7 | 'use strict'; |
||
8 | if (this == null) { |
||
0 ignored issues
–
show
|
|||
9 | throw new TypeError('Array.prototype.includes called on null or undefined'); |
||
10 | } |
||
11 | |||
12 | var O = Object(this); |
||
13 | var len = parseInt(O.length, 10) || 0; |
||
14 | if (len === 0) { |
||
15 | return false; |
||
16 | } |
||
17 | var n = parseInt(arguments[1], 10) || 0; |
||
18 | var k; |
||
19 | if (n >= 0) { |
||
20 | k = n; |
||
21 | } else { |
||
22 | k = len + n; |
||
23 | if (k < 0) { |
||
24 | k = 0; |
||
25 | } |
||
26 | } |
||
27 | var currentElement; |
||
28 | while (k < len) { |
||
29 | currentElement = O[k]; |
||
30 | if (searchElement === currentElement || |
||
31 | (searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN |
||
32 | return true; |
||
33 | } |
||
34 | k++; |
||
35 | } |
||
36 | return false; |
||
37 | } |
||
38 | }) |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
39 | } |
||
40 | } |
||
0 ignored issues
–
show
There should be a semicolon.
Requirement of semicolons purely is a coding style issue since JavaScript has specific rules about semicolons which are followed by all browsers. Further Readings: ![]() |
|||
41 |
Generally, it is recommended to use strict comparison whenever possible and not to rely on the weaker type-juggling comparison operator.
Read more about comparison operations.