旧的反应和 IE11 polyfills
old react and IE11 polyfills
我是 运行 React 0.13,无法升级(长话短说)。不能使用 Babel-Polyfill。
我需要让应用程序与 IE11 兼容,所以我需要实现很多 polyfill。
我如何或如何将 polyfill 包含在单个文件中并使该文件全局可见?
我有一个只包含 polyfill 的文件(比如这个)
但我不确定如何将其包含在默认情况下仅在全局可见。
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
您可以实现一个包装所有 polyfill 的函数,并将其导入到您需要的任何地方。
export function loadCustomPolyfills() {
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
..
};
}
//other polyfills
}
在你的入口点文件中,在开头
import { loadCustomPolyfills } from './custom-polyfills';
loadCustomPolyfills();
我是 运行 React 0.13,无法升级(长话短说)。不能使用 Babel-Polyfill。 我需要让应用程序与 IE11 兼容,所以我需要实现很多 polyfill。
我如何或如何将 polyfill 包含在单个文件中并使该文件全局可见?
我有一个只包含 polyfill 的文件(比如这个)
但我不确定如何将其包含在默认情况下仅在全局可见。
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
'use strict';
if (target == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
target = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source != null) {
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
}
return target;
};
}
您可以实现一个包装所有 polyfill 的函数,并将其导入到您需要的任何地方。
export function loadCustomPolyfills() {
if (typeof Object.assign != 'function') {
Object.assign = function(target) {
..
};
}
//other polyfills
}
在你的入口点文件中,在开头
import { loadCustomPolyfills } from './custom-polyfills';
loadCustomPolyfills();