OlexG / Patterns

Simples demos of various design patterns in javascript and typescript.
0 stars 0 forks source link

Builders might be better off using Object.defineProperty #2

Closed mattfbacon closed 3 years ago

mattfbacon commented 3 years ago

In case you don't want these attributes (that would probably be present in a class) to be, e.g., enumerable, you can use Object.defineProperty with enumerable: false. There is also a read-only attribute, as well as getters and setters.

mattfbacon commented 3 years ago

This applies to Creational/builder.js.

OlexG commented 3 years ago

yeah but in this case, it's fine if they are enumerable and changeable though thanks for the suggestion, I did not know about the defineProperty method. I think builder.js demonstrates the essence of builder pattern fine with or without it.

mattfbacon commented 3 years ago

It's just that a class with the same fields wouldn't be enumerable so since you're trying to simulate multiple inheritance (at least from what I can tell) it's not actually the same thing.