Classes, Inheritance, Functional programming - 401-advanced-javascript-v/seattle-javascript-401d29 GitHub Wiki

When you try to access a property on the new object, it checks the object’s own properties first. If it doesn’t find it there, it checks the [Prototype](/401-advanced-javascript-v/seattle-javascript-401d29/wiki/Prototype), and so on up the prototype chain until it gets back to Object.prototype, which is the root delegate for most objects.

class

class Greeter { constructor (name) { this.name = name || 'John Doe'; } hello () { return Hello, my name is ${ this.name }; } }

const george = new Greeter('George');

const msg = george.hello();

console.log(msg); // Hello, my name is George

Factory

const proto = { hello () { return Hello, my name is ${ this.name }; } };

const greeter = (name) => Object.assign(Object.create(proto), { name });

const george = greeter('george');

const msg = george.hello();

console.log(msg);

Functional Inheritance

Functional inheritance makes use of a factory function, and then tacks on new properties using concatenative inheritance.