-
Notifications
You must be signed in to change notification settings - Fork 185
Base Class Reference
The AV.Base
class makes it easier to extend CoffeeScript classes from normal JavaScript. Many of the classes in Aurora that you'd like to extend inherit from the Base class, and in fact, all classes that inherit from AV.EventEmitter
also inherit from AV.Base
.
The class level extend
method creates and returns a new class extending from the class on which it is called. It accepts either an object containing the methods and properties to be added to the class's prototype or a function to be invoked in order to initialize the prototype.
If a function is passed, it is called with the new class as an argument and as the this
binding. Simply add your methods to this.prototype
to add them to the class. The function initialization option is useful if you want to use it as a closure for private data. For example:
Dog = Animal.extend(function(Dog) {
this.prototype.bark = function() {
// do something
}
Dog.prototype.run = function() {
// do something else
}
});
Within the methods added to the class, you can use this._super() to call the super class's implementation of the current method. For example:
Dog = Animal.extend({
move: function(howFar) {
this._super(howFar);
// custom stuff here
}
});