Multiple ways of extending javascript objects
/**
* One-way reference from subclass to superclass (instance)
* Most of the time this is what you want. It should be done
* before adding other methods to Subclass.
*/
ChildClass.prototype = new SuperClass();
/**
* Two-way reference
* Superclass will also get any Subclass methods added later.
*/
ChildClass.prototype = SuperClass.prototype;
/**
* Cloning behavior
* This does not setup a reference, so instanceof will not work.
*/
angular.extend(ChildClass.prototype, SuperClass.prototype);
/**
* Enhancing a single instance
* This could be used to implement the decorator pattern.
*/
angular.extend(subClassInstance, SuperClass.prototype);