Prototyping
Contents
This technique allows a developer to define features that can accessed directly from a game object. For example,
one could define a custom travelTo
method on Creep
as an alternative to moveTo
. It is even possible
to overwrite/redefine existing properties/methods (known as "monkey patching"),
though this can have unintended side-effects.
For more details and examples, check out the wonderfully-written official documentation.
Caveats
Static class methods and properties (ex: all of the fields on Game
) cannot be modified via prototypes.
Some game types (ex: RoomPosition
) are not interned.
As such, if a memoized property is defined on such a class's prototype and later invoked on an instance of that class,
the memoized result won't necessarily be available from other instances representing the same room position.