我正在使用find () function 我的一個專案。官方檔案https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find說不支持 Internet Explorer。我還能用什么?
uj5u.com熱心網友回復:
polyfill 是一種代碼,它提供您通常期望瀏覽器原生提供的功能。這是 Array.find 的 polyfill
if (!Array.prototype.find) {
Array.prototype.find = function(predicate) {
if (this === null) {
throw new TypeError('Array.prototype.find called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i ) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return value;
}
}
return undefined;
};
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/427829.html
標籤:javascript IE浏览器 找 跨浏览器
