Composer.js
- Start
- Class system
- Eventing
- Utilities
- Base
- Model
- Collection
- Controller
- Controller xdom
- Relational model
- Filter collection
- List controller
- Router
- Best practices
- Building/load order
- Tests
Class system
The Composer class system is the base building block of all the objects Composer provides (Model, Controller, etc). It is designed to be a standalone component that doesn’t necessarily need to be part of Composer.
Composer.Class
This is the main export of the class system:
NOTE: Composer.Class(...)
and Composer.Class.extend(...)
are the same.
Extending
Classes can be extended two ways. The vanilla, simple way is MyClass.extend
.
Class.extend :: function(definition)
Composer.merge_extend :: function(class, array_of_property_names)
Another way, which is used internally in Composer, is very similar to the above extension method. It allows a class to additively extend certain static properties of the parent class. This sounds a bit esoteric, so let’s dive in:
This is mainly used in Controllers (the events
and elements
properties) as well as the Relational Model’s
relations
property.
Constructors
A class contructor is specified by its initialize
function:
Parent methods
The class system allows calling parent methods using this.parent()
:
Mixins
The class system supports mixins. When using these, it will merge in objects from the mixins and the object being created. This can be useful for extending the functionality of classes without using inheritance structures.
Mixins are defined as a special key in the class, _mixins
, which is a function
that returns an array of mixin objects: