2021-06-24 使得对象有prototype

2021-06-24  本文已影响0人  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())
  
上一篇 下一篇

猜你喜欢

热点阅读