Object.assign不兼容IE

问题:Object.assign导致IE浏览器、电脑微信客户端网页无法正常打开(Object.assign报错)

问题页面截图:

解决方法:

在Object.assign(window, view);前面加以下代码,重写该方法:

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;
  };
}
Object.assign(window, view);

猜你喜欢

转载自blog.csdn.net/tt18473481961/article/details/86237529