method 'assign' not supported in IE, what to do

和自甴很熟 提交于 2019-11-30 12:53:09

IE doesn't support Object.assign()

Use polyfil

    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;
  };
}

If you are using babel

npm install --save-dev babel-plugin-transform-object-assign

using .babelrc

{
  "plugins": ["transform-object-assign"]
}

you can find other methods here

If you are using jquery, you can try jQuery.extend( target [, object1 ] [, objectN ] ). Your code:

const eventData = $.extend({}, eventItem);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!