new和Object.create()

Object.create()

Object.creat = function (o) {
  function F() {};
  F.prototype = o;
  return new F;
}

new

function Person (name) {
  this.name = name;
}

function createObject (Base) {
  var args = [].slice.call(arguments, 1);
  var o = new Object;
  o.__proto__ = Base.prototype;
  Base.protype.constructor = Base;
  Base.apply(o, args);
  return o;
}
Paste_Image.png

推荐阅读

  • new的原理
  • 你不知道的javascript之Object.create 和new区别

你可能感兴趣的:(new和Object.create())