美文网首页
new和Object.create()

new和Object.create()

作者: 时间de歌 | 来源:发表于2017-10-17 18:51 被阅读1次

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和Object.create()

      本文链接:https://www.haomeiwen.com/subject/hrieextx.html