Show HN: How I use JavaScript Prototypal Inheritance in my game inventory system
pixdeo.com
pixdeo.com
It is having three layers of instantiation.
Typically in a data-driven game engine you have some base class that handles the behavior of, say, a collectible. (In a modern engine this would be a component, rather than a base class).
Then you load data and instantiate a number of those components for different types of collectible: health, powerup, etc.
Then you instantiate those for a specific collectible (the health pack at location X,Y,Z in level A).
That doesn't map elegantly onto the class/instance dichotomy. The mapping is tricky enough that there are different ways of doing it: you can have a different kind of class in the middle layer that acts as a factory for your third layer instances; you can have an 'archetype' mechanism, where instances at the second level are copied to make instances at the third; or you make instances at the third level have a reference to their 'type' (instances at the second) and delegate queries through to them. There are many other approaches.
But that three layer data-driven problem goes away when you can just inherit as many times as you like.
In most large game engines, there is a poorly architected buggy version of prototypical inheritance.
http://steve-yegge.blogspot.com/2008/10/universal-design-pat...
`var jalapeño = _.defaults(jalapenoFromJSON, apple);`
Do you write Javascript? Do the world a favor and learn how to use Prototypes instead of using classes for everything.