How does the Object Linked to Other Objects pattern work?

3

What is the OLOO pattern? How does it work? What's your difference to Prototype Pattern? What is the advantage of using each one?

    
asked by anonymous 30.03.2017 / 15:43

1 answer

1

The OLOO pattern creates a prototype string without the need for intermediate semantics (eg prototype , new , function ) to create and bind objects, making it simpler than the standard Prototype .

The OLOO differs from Prototype essentially in the syntax (how objects are built and linked):

See 2 examples in each pattern in the construction of prototype :

Prototype pattern:

function Abc() {}
Abc.prototype.y = 1;

OLOO pattern:

var AbcObj = { y: 1 };

See that in OLOO the syntax is simpler and more direct, without intermediation of the semantics prototype and function .

Now examples of how each pattern links one object to another:

Prototype pattern:

function Abc() {}

function Tst() {}
Tst.prototype = Object.create(Abc.prototype);

or

function Abc() {}

var Tst = new Abc();

OLOO pattern:

var AbcObj = {};

var TstObj = Object.create(AbcObj);

Note that in OLOO just create a variable ( var TstObj ) and bind directly to the other object ( AbcObj ) using Object.create() , without the need for other semantics, such as prototype , new and function .

Conclusion:

You can not define the " advantage of each " because the two patterns produce the same result; however, the OLOO pattern is much simpler than the Prototype pattern because it has a "leaner" syntax, creating and linking objects directly and saving semantics. In this concept, it becomes more advantageous to use the OLOO standard than the Prototype standard.

The material on this page provides some information about the OLOO pattern.

    
19.10.2017 / 06:54