OLOO questions

In notebook:
FrontEndMasters Advanced JavaScript
Created at:
2016-10-07
Updated:
2016-10-08
Tags:
Fundamentals JavaScript
- Can you delegate to more than one object?

Not possible. There's only one prototype chain.

- So bar cannot have an init function?

He moved the final init to Foo
Or, if the question was about shadowing, then he says it's really not a good idea, it will create a lot of brittle complexity.

There are to steps to "create" your object:
  1. var b1 = Object.create(Bar);
  2. ​b1.init("b1");
But you can for example in the first section of your app do the first step, and only do the second later on, in a second part of your code

- What about performance? Doesn't we have many instances of an object (​Object.create()​) versus delegating with the prototype chain?

We don't have many instances. It's the exact same mechanism as with the ​prototype​. There's still just one ​init​ function.
The usual pattern is that a central object holds the methods and it's the leaf notes that hold state and delegate to the central object.

- Real world example of OLOO style?

It was still very new when he held the workshop. 

- Explain object.Create()

will do later

- What objections does he get when advocates object delegation vs classes?

People think that they've been taught that classes are the only proper way to design software. That real-world problems map best to classes (wrong).
What he proposes is that there these two patterns, and that classes go against how JS works and delegation is how the language was designed to work.
The diagram of the OLOO pattern.

Note that there are no functions, only objects
diagramWe directly create the object and their relationshipsThe polyfill for ​Object.create()​:
  if(!Object.create) {
  Object.create = function (o) {
    function F() {}
    F.prototype = o;
    return new F();
  };
}