Fix #1027: create IE11 Array polyfills `find` and `findIndex` in such a way that they are not iterable
This commit is contained in:
parent
70a2f94693
commit
b6235a8d23
|
@ -7,6 +7,8 @@ https://github.com/josdejong/jsoneditor
|
||||||
|
|
||||||
- Fixed broken link to the Ace editor website (https://ace.c9.io/).
|
- Fixed broken link to the Ace editor website (https://ace.c9.io/).
|
||||||
Thanks @p3x-robot.
|
Thanks @p3x-robot.
|
||||||
|
- Fix #1027: create IE11 Array polyfills `find` and `findIndex` in such a way
|
||||||
|
that they are not iterable.
|
||||||
|
|
||||||
|
|
||||||
## 2020-05-24, version 9.0.0
|
## 2020-05-24, version 9.0.0
|
||||||
|
|
|
@ -25,24 +25,32 @@ if (typeof Element !== 'undefined') {
|
||||||
// simple polyfill for Array.findIndex
|
// simple polyfill for Array.findIndex
|
||||||
if (!Array.prototype.findIndex) {
|
if (!Array.prototype.findIndex) {
|
||||||
// eslint-disable-next-line no-extend-native
|
// eslint-disable-next-line no-extend-native
|
||||||
Array.prototype.findIndex = function (predicate) {
|
Object.defineProperty(Array.prototype, 'findIndex', {
|
||||||
for (let i = 0; i < this.length; i++) {
|
value: function (predicate) {
|
||||||
const element = this[i]
|
for (let i = 0; i < this.length; i++) {
|
||||||
if (predicate.call(this, element, i, this)) {
|
const element = this[i]
|
||||||
return i
|
if (predicate.call(this, element, i, this)) {
|
||||||
|
return i
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return -1
|
||||||
return -1
|
},
|
||||||
}
|
configurable: true,
|
||||||
|
writable: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Polyfill for Array.find
|
// Polyfill for Array.find
|
||||||
if (!Array.prototype.find) {
|
if (!Array.prototype.find) {
|
||||||
// eslint-disable-next-line no-extend-native
|
// eslint-disable-next-line no-extend-native
|
||||||
Array.prototype.find = function (predicate) {
|
Object.defineProperty(Array.prototype, 'find', {
|
||||||
const i = this.findIndex(predicate)
|
value: function (predicate) {
|
||||||
return this[i]
|
const i = this.findIndex(predicate)
|
||||||
}
|
return this[i]
|
||||||
|
},
|
||||||
|
configurable: true,
|
||||||
|
writable: true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Polyfill for String.trim
|
// Polyfill for String.trim
|
||||||
|
|
Loading…
Reference in New Issue