javascript – Como funciona o pattern Object Linked to Other Objects?


What is the OLOO pattern? How does it work? How is it different from Prototype Pattern? What is the advantage of using each one?


The OLOO pattern creates a prototype chain without the need to intermediate other semantics (eg prototype , new , function ) to create and link objects, making it simpler than the Prototype pattern.

OLOO differs from Prototype essentially in its syntax (how the objects are constructed and linked between them):

See 2 examples in each pattern in prototype construction:

Prototype pattern:

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

OLOO pattern:

var AbcObj = { y: 1 };

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

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

Prototype pattern:

function Abc() {}

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


function Abc() {}

var Tst = new Abc();

OLOO pattern:

var AbcObj = {};

var TstObj = Object.create(AbcObj);

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


It is not possible to define the " advantage of each ", as 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 is more advantageous to use the OLOO pattern than the Prototype pattern.

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

Scroll to Top