首页  >  问答  >  正文

javascript - 方法Object()里面传参数和不传参数有什么区别?

比如这里target = Object(target)和target = Object()或者target = new Object()有什么区别?

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;
  };
}
过去多啦不再A梦过去多啦不再A梦2663 天前814

全部回复(2)我来回复

  • 天蓬老师

    天蓬老师2017-07-05 11:10:24

    你不给参数的话他就是个空对象。。。

    回复
    0
  • 为情所困

    为情所困2017-07-05 11:10:24

    https://developer.mozilla.org...这篇文章讲得很清楚

    回复
    0
  • 取消回复