Echo JS 0.11.0

zhirzh 305 days ago.
Can anyone explain to me the differences between prototype, constructor and __proto__?

ksmithut 305 days ago. link 3 points
So prototype exists on a function. Everytime someone uses the new keywork with
that function, the instance gets the methods defined on the prototype. The
`__proto__` property is essentially a shortcut to get the prototype of the
constructor. The `constructor` is a reference to the prototype function that
the instance was instantiated with. See the below example, hope that helps

function User(name) { = name || 'Unknown'

User.prototype.greet = function() {
  console.log('Hello ' +

var user = new User('Billy')

console.log(user.__proto__ === User.prototype) // true
console.log(user.constructor === User) // true
console.log(user.constructor.prototype === user.__proto__) // true
console.log(user.greet === user.__proto__.greet) // true
console.log(user.greet === User.prototype.greet) // true