diff --git a/HISTORY.md b/HISTORY.md index d567753..5cb6800 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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 diff --git a/src/js/polyfills.js b/src/js/polyfills.js index 0c59ac2..8c42bd1 100644 --- a/src/js/polyfills.js +++ b/src/js/polyfills.js @@ -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