I've been trying to wrap my head around Object Composition for a while and I can't seem to find the "correct way" to do the same I was doing before with OOP. Lets say I have a class Entity with 3 variables, with OOP I would just create a class Entity and all the children of this class would have these 3 properties, but using object composition I can't seem to understand how I'm supposed to mimic this inheritance.
const Entity = {
let self = {
x: 0,
y: 0,
z: 0,
}
Do I need to create these properties in all other objects I create that need them? Or is there a better way to reuse these properties?
const ObjectX = {
let state = {
x: 0,
y: 0,
z: 0,
abc: 0,
cba: 0,
return Object.assign(state, canDoX);
}
const ObjectY = {
let state = {
x: 0,
y: 0,
z: 0,
foo: 0,
bar: 0,
return Object.assign(state, canDoY);
}