-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolyfill-array.js
executable file
·63 lines (52 loc) · 1.74 KB
/
polyfill-array.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
/*!
* Version: 1.0
* Started: 14-06-2022
* Updated: 14-06-2022
* Author : paramana (hello AT paramana DOT com)
*
*/
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function indexOf(member, startFrom) {
'use strict';
/*
In non-strict mode, if the `this` variable is null or undefined, then it is
set to the window object. Otherwise, `this` is automatically converted to an
object. In strict mode, if the `this` variable is null or undefined, a
`TypeError` is thrown.
*/
if (this == null)
throw new TypeError('Array.prototype.indexOf() - can\'t convert `' + this + '` to object');
var index = isFinite(startFrom) ? Math.floor(startFrom) : 0,
that = this instanceof Object ? this : new Object(this),
length = isFinite(that.length) ? Math.floor(that.length) : 0;
if (index >= length)
return -1;
if (index < 0)
index = Math.max(length + index, 0);
if (member === undefined) {
/*
Since `member` is undefined, keys that don't exist will have the same
value as `member`, and thus do need to be checked.
*/
do {
if (index in that && that[index] === undefined)
return index;
}
while (++index < length);
}
else {
do {
if (that[index] === member)
return index;
}
while (++index < length);
}
return -1;
};
}
if (!Array.isArray) {
Array.isArray = function(arg) {
'use strict';
return Object.prototype.toString.call(arg) === '[object Array]';
};
}