IE11不支持fill() [英] fill() not supported in IE11
本文介绍了IE11不支持fill()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下语法.我是ES6语法的新手.
I have the following syntax. I am new to ES6 syntax.
const renderLoading = () => Array(20).fill('').map(() => <ExpampleLine/>);
Internet Explorer不支持fill()命令.是否有单独的fill()解决方案,还是我应该重写整个语法.需要有关语法的帮助.
The fill() command is not supported in Internet explorer. Is there any work around for fill() alone or should I rewrite whole syntax. Need some help with the syntax.
推荐答案
使用polyfill:
Use a polyfill:
if (!Array.prototype.fill) {
Object.defineProperty(Array.prototype, 'fill', {
value: function(value) {
// Steps 1-2.
if (this == null) {
throw new TypeError('this is null or not defined');
}
var O = Object(this);
// Steps 3-5.
var len = O.length >>> 0;
// Steps 6-7.
var start = arguments[1];
var relativeStart = start >> 0;
// Step 8.
var k = relativeStart < 0 ?
Math.max(len + relativeStart, 0) :
Math.min(relativeStart, len);
// Steps 9-10.
var end = arguments[2];
var relativeEnd = end === undefined ?
len : end >> 0;
// Step 11.
var final = relativeEnd < 0 ?
Math.max(len + relativeEnd, 0) :
Math.min(relativeEnd, len);
// Step 12.
while (k < final) {
O[k] = value;
k++;
}
// Step 13.
return O;
}
});
}
这篇关于IE11不支持fill()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文