The class module provides object-oriented programming techniques, including inheritance and mixins, to the Anchor platform.
$ component install anchorjs/class
$ volo add anchorjs/class
To inherit a class from a subclass, invoke inherits()
, passing the constructor
and super constructor as arguments.
function Cat() {
Cat.super_.call(this);
};
clazz.inherits(Cat, Animal);
To augment a class with functions of a mixin object, invoke augment()
.
var HousePet = {
eat: function() {},
sleep: function() {}
}
clazz.augment(Cat, HousePet);
This module uses the AMD format. To include in component builds, use component-amd:
component build -u component-amd
To run tests in a browser, execute the Make target for the desired browser:
$ make test-chrome
$ make test-firefox
$ make test-safari
Headless tests can be executed directly from a terminal:
$ make test-phantomjs
Copyright (c) 2012-2013 Jared Hanson <http://jaredhanson.net/>