dojo.declare
<script src="../../js/dojo.js"></script>
defined in dojo/_base/declare.js
Create a constructor using a compact notation for inheritance and prototype extension.
All superclasses (including mixins) must be Functions (not simple Objects).
Mixin ancestors provide a type of multiple inheritance. Prototypes of mixin ancestors are copied to the new class: changes to mixin prototypes will not affect classes to which they have been mixed in.
"className" is cached in "declaredClass" property of the new class.
parameter | type | description |
---|---|---|
className | String | The name of the constructor (loosely, a "class") stored in the "declaredClass" property in the created prototype |
superclass | Function | May be null, a Function, or an Array of Functions. If an array, the first element is used as the prototypical ancestor and any following Functions become mixin ancestors. |
props | Object | An object whose properties are copied to the created prototype. Add an instance-initialization function by making it a property named "constructor". |
Examples
Example 1
dojo.declare("my.classes.bar", my.classes.foo, {
// properties to be added to the class prototype
someValue: 2,
// initialization function
constructor: function(){
this.myComplicatedObject = new ReallyComplicatedObject();
},
// other functions
someMethod: function(){
doStuff();
}
);