Fix #1027: create IE11 Array polyfills `find` and `findIndex` in such a way that they are not iterable

This commit is contained in:
josdejong 2020-06-23 21:22:21 +02:00
parent 70a2f94693
commit b6235a8d23
2 changed files with 22 additions and 12 deletions

View File

@ -7,6 +7,8 @@ https://github.com/josdejong/jsoneditor
- Fixed broken link to the Ace editor website (https://ace.c9.io/).
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

View File

@ -25,24 +25,32 @@ if (typeof Element !== 'undefined') {
// simple polyfill for Array.findIndex
if (!Array.prototype.findIndex) {
// eslint-disable-next-line no-extend-native
Array.prototype.findIndex = function (predicate) {
for (let i = 0; i < this.length; i++) {
const element = this[i]
if (predicate.call(this, element, i, this)) {
return i
Object.defineProperty(Array.prototype, 'findIndex', {
value: function (predicate) {
for (let i = 0; i < this.length; i++) {
const element = this[i]
if (predicate.call(this, element, i, this)) {
return i
}
}
}
return -1
}
return -1
},
configurable: true,
writable: true
})
}
// Polyfill for Array.find
if (!Array.prototype.find) {
// eslint-disable-next-line no-extend-native
Array.prototype.find = function (predicate) {
const i = this.findIndex(predicate)
return this[i]
}
Object.defineProperty(Array.prototype, 'find', {
value: function (predicate) {
const i = this.findIndex(predicate)
return this[i]
},
configurable: true,
writable: true
})
}
// Polyfill for String.trim