new和Object.create()

2017-10-17  本文已影响1人  时间de歌

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

推荐阅读

上一篇 下一篇

猜你喜欢

热点阅读