- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Internet Explorer 上使用 Angular 应用程序时遇到问题。它在任何地方都可以毫无问题地运行(Chrome、Mozilla、Edge),但在 IE 上不行。
我已经使用 Developer Explorer 分析了错误所在,并返回错误发生在以下行:
myDataSet[index - 1].data = Array.from(tmp);
这是我收到的以下错误消息:
Object does not support property or method from at Anonymous function....(etc.)
我在那里做的是,我有一个名为 tmp
的 Set()
,其中包含以下数据:
之后,我只是从这个 Set
创建一个简单的数组对象。
如何解决这个问题?
编辑
根据建议,我已将以下代码添加到我的应用程序中:
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;
// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);
// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError("Array.from requires an array-like object - not null or undefined");
}
// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}
最佳答案
以下文档模式不支持
Array.from
:Quirks、Internet Explorer 6 标准、Internet Explorer 7 标准、Internet Explorer 8 标准、Internet Explorer 9 标准、Internet Explorer 10 标准、Internet Explorer 11项标准。 Windows 8.1 不支持 ( compatibility reference )
只需将以下代码添加到您的页面 ( JS code was copied from developer.mozilla.org )。它将模拟 ES6 的 Array.from 方法。
Array.from was added to the ECMA-262 standard in the 6th edition; as such it may not be present in other implementations of the standard. You can work around this by inserting the following code at the beginning of your scripts, allowing use of Array.from in implementations that don't natively support it. This algorithm is exactly the one specified in ECMA-262, 6th edition, assuming Object and TypeError have their original values and that callback.call evaluates to the original value of Function.prototype.call. In addition, since true iterables can not be polyfilled, this implementation does not support generic iterables as defined in the 6th edition of ECMA-262.
if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};
// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;
// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);
// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError("Array.from requires an array-like object - not null or undefined");
}
// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}
// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}
// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);
// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);
// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}
关于javascript - Internet Explorer 上 Array.from 的替代方案或 polyfill,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36810940/
https://github.com/Yaffle/EventSource 我使用上面的是因为我想获得在 IE11 中工作的 promise ,我已经用 npm 安装了它但不确定我应该如何实现它。我在
有没有办法“摇树”babel-polyfill,这样只有我使用的功能是 polyfill? 也就是说,如果我从不在我的代码中使用 String.padStart,则不应包含它的 polyfill。 最
在我的入口点中使用 babel 转换将 babel-polyfill 导入到 Browserify 后,IE11 仍然提示 Object.assign。除了 Object.assign 之外,我的项目
这里是 Polyfill 新手。我对这个简单的例子完全感到困惑,在这个例子中我想初始化一个类型化数组: var x = new Uint8Array(3).fill(42); console.log(
我正在使用 ChildNode.remove()并且我由 Mozilla 描述我需要一个用于 IE 的 polyfill。我正在使用配置了 babel-polyfill 的 webpack: "ba
我正在使用 nuxt vuetify 模板构建一个静态站点,虽然它很棒并且提供了很多已经为我完成的配置和设置,但我发现很难让我的站点在 Internet Explorer (11) 上顺利运行。 由于
使用 core-js 填充的函数(例如,babel-polyfill)显示为原生。 Promise.race.toString() 产生: function race() { [native
我有以下实用程序: // Utility function to remove base64 URL prefix and store base64-encoded string in
我得到的错误 Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has b
我正在学习基于 React 的 Udemy 类(class)(这是 Brad Schiff 为我们其他人准备的 React 类(class) here),我收到一个与 webpack 相关的错误,导致
我将 Ionic 3 项目升级为 Ionic 4 项目。使用“ionic serve”启动服务器时,我总是会收到上述错误。 我试过很多东西,例如: 在 polyfills.ts 文件中, (windo
我知道每个已知的浏览器都支持“decodeURIComponent”,但我试图通过 polyfill 来更好地理解它。 Atob、Btoa 有很多 polyfill……但出于某种原因,我没有找到任何用
我无法理解为什么检查对应于行 if (i in t) - 第 18 行放在 filter function polyfill 中: if (!Array.prototype.filter) { A
我正在尝试为传播运算符创建一个 polyfill。我的目标是创建类似于扩展运算符的东西,我可以使用三重 @@@ 符号代替三重点。 例如,在 ES6 中 function sum(x, y, z) {
This article启发我将我为 React 应用程序加载的 polyfill 外部化,并且只为需要它们的浏览器加载它们。一个简单的测试: function browserSupportsAllF
我创建了一个自托管 ServiceStack 服务,该服务基于其 showcase chat application 在 Windows 服务中运行。 。 但是,我没有进一步讨论的是尝试将客户端编写为
我正在开始一个新项目,目标是 MSVC、GCC(最新)、GCC 4.3 ARM 等等。我们构建的 waf 构建系统具有编译器的 C++11 功能检测。 我现在为 C++11 目标编译器中的所有功能提供
我正在寻找一种工具,它可以让我利用 native HTML5 拖放功能,并填充对过去浏览器的支持。 有这样的东西吗? Modernizr 的页面 (https://github.com/Moderni
是否有一个 polyfill 来处理 Safari 4 (iOS) 和 IE 中的 CSS 背景大小调整 最佳答案 可以试试这个。 http://nooshu.com/jquery-plug-in-s
我正在构建一个我的目标群体非常普遍的网站(13 岁到 oo,所以你好 IE9,你好古老的 android 浏览器),所以我需要 polyfills 来处理一些东西(viewport,calc 等)。在
我是一名优秀的程序员,十分优秀!