__proto__ VS. prototype in JavaScript

后端 未结 30 1949
爱一瞬间的悲伤
爱一瞬间的悲伤 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:41

    To make it a little bit clear in addition to above great answers:

    function Person(name){
        this.name = name
     }; 
    
    var eve = new Person("Eve");
    
    eve.__proto__ == Person.prototype //true
    
    eve.prototype  //undefined
    

    Instances have __proto__, classes have prototype.

提交回复
热议问题