Echo JS 0.11.0

<~>
ksmithut 307 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

```js
function User(name) {
  this.name = name || 'Unknown'
}

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

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
```

Replies