admin管理员组文章数量:1335183
I setup webpack + babel config
webpack.config.js
...
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
...
.babelrc
{
"plugins": ["lodash", "transform-object-rest-spread"],
"presets": [
["env", {
"targets": [
"> 4%",
"ie 11",
"safari 8"
]
}],
"react",
"react-optimize"
],
"env": {
"test": {
"presets": ["es2015", "react"]
}
}
}
In google chrome everything is ok, but in IE 11i have an error
Object doesn't support property or method 'assign'
I setup webpack + babel config
webpack.config.js
...
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
...
.babelrc
{
"plugins": ["lodash", "transform-object-rest-spread"],
"presets": [
["env", {
"targets": [
"> 4%",
"ie 11",
"safari 8"
]
}],
"react",
"react-optimize"
],
"env": {
"test": {
"presets": ["es2015", "react"]
}
}
}
In google chrome everything is ok, but in IE 11i have an error
Share Improve this question asked May 6, 2017 at 18:26 Pavel PerevezencevPavel Perevezencev 2,9784 gold badges31 silver badges53 bronze badgesObject doesn't support property or method 'assign'
2 Answers
Reset to default 5You would need to add the object assign transform as well Check https://babeljs.io/docs/plugins/transform-object-assign/
Also notice that it is best practice to include a polyfill instead. The MDN usually gives a polyfill code for ES2015 features. Check https://developer.mozilla/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
For the record, it is:
if (typeof Object.assign != 'function') {
Object.assign = function(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
};
}
You want to include this code in your app for browsers that do not support Object.assign. The Babel transform plugin referred above also remends this approach when building an app and not a library.
It looks like babel pilation doesn't work. Object.assign is ECMAScript 2015 feature and chrome supports it without pilation.
本文标签: javascriptObject doesn39t support property or method 39assign39Stack Overflow
版权声明:本文标题:javascript - Object doesn't support property or method 'assign' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382106a2464299.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论