__proto__ VS. prototype in JavaScript

后端 未结 30 1912
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-21 06:14

This figure again shows that every object has a prototype. Constructor function Foo also has its own __proto__ which is Function.prototype, a

30条回答
  •  广开言路
    2020-11-21 06:37

    (function(){ 
          let a = function(){console.log(this.b)};
          a.prototype.b = 1;
          a.__proto__.b = 2;
          let q = new a();
          console.log(a.b);
          console.log(q.b) 
        })()

    Try this code to understand

提交回复
热议问题