Components are self-contained pieces of functionality that can be added onto and removed from objects. The allow for a more dynamic functionality tree than using inheritance (i.e. by favoring composition over inheritance) and are added and removed on the fly at runtime. (yes, I know everything in JS is at runtime, but you know what I mean, geez)
Combining components with events makes it easy to create reusable pieces of functionality that can be decoupled from each other.
The base class for components. These are usually not derived directly but are instead
created by calling
Q.register to register a new component given a set of methods the
component supports. Components are created automatically when they are added to a
Q.GameObject with the
Many components also define an
added method, which is called automatically by the
init constructor after a component has been added to an object. This is a good time
to add event listeners on the object.
destroy is called automatically when a component is removed from an entity. It is
not called, however, when an entity is destroyed (for performance reasons).
It's job is to remove any methods that were added with
extend and then remove and
debind itself from the entity. It will also call
destroyed if the component has
a method by that name.