search

Home  >  Q&A  >  body text

javascript - What is the difference between passing parameters and not passing parameters in the method Object()?

For example, what is the difference between target = Object(target) and target = Object() or 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梦2769 days ago879

reply all(2)I'll reply

  • 天蓬老师

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

    If you don’t give parameters, it will be an empty object. . .

    reply
    0
  • 为情所困

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

    https://developer.mozilla.org...This article explains it very clearly

    reply
    0
  • Cancelreply