美文网首页
2021-06-24 使得对象有prototype

2021-06-24 使得对象有prototype

作者: 0说 | 来源:发表于2021-06-24 23:18 被阅读0次
      const person = function (name){
        this.name = name
      }
      person.prototype.getName = function(){
        return this.name
      }

      let oF = function() {
        let obj = {};
        let c = [].shift.call(arguments)
        obj.__proto__ = c.prototype
        c.apply(obj, arguments);
        return obj
      }
  
      let a = oF(person, '666666')
      console.log(a)
      console.log(a.name)
      console.log(a.getName())
  

相关文章

网友评论

      本文标题:2021-06-24 使得对象有prototype

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