Functiondojo.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.

Usage

function (/*String*/ className, /*Function*/ superclass, /*Object*/ props) (view source)
parametertypedescription
classNameStringThe name of the constructor (loosely, a "class") stored in the "declaredClass" property in the created prototype
superclassFunctionMay 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.
propsObjectAn 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();
    }
);

Jump to FunctionsNamespacesBack to top

Jump to NamespacesFunctionsBack to top

Function_delegate(base, mixin)
Function_extend(props)