Reading Class 02 - meron-401n14/seattle-javascript-401n14 GitHub Wiki

**Inheritance **

JavaScript is one of the most expressive programming language ever created. One of its best features is the ability to create and inherit from objects without classes and class inheritance.

Method delegation can preserve memory resources because you only need one copy of each method to be shared by all instances.

In JavaScript, any function can create new objects . When it is not a constructor function , it is called a factory function.

You can avoid property delegation by setting the prototype to 'null' using Object.create(null).

One major drawback to delegation is that it's not very good for storing state. If you try to state as objects or arrays, mutating any member of the object or array will mutate the member for every instance that shares the prototype.

Cloning is a great way to store default state for objects: This process is commonly achieved using Object.assign().

Composition over class inheritance :

Const effect = compose(delay, distortion, robovoice);

Composition is : simpler, more expressive, more flexible

A stamp is a composable factory function that returns object instances based on its descriptor.

Stamps have a method called .compose():

Descriptor : or Composable descriptor is a meta data object which contains the information necessary to create an object instance.

A descriptor contains :

methods — A set of methods that will be added to the object’s delegate prototype. properties — A set of properties that will be added to new object instances by assignment. initializers — An array of functions that will run in sequence. Stamp details and arguments get passed to initializers. staticProperties — A set of static properties that will be copied by assignment to the stamp.

compose(…composables: […Composable]) => Stamp takes any number of composables and returns a new stamp. init(…functions: […Function]) => Stamp takes any number of initializer functions and returns a new stamp.