W3cubDocs

/Dojo

dojo/_base/declare.__DeclareCreatedObject

Summary

dojo/_base/declare() returns a constructor C. new C() returns an Object with the following methods, in addition to the methods and properties specified via the arguments passed to declare().

Note: This is not a real constructor, but just a description of the type of object that should be passed as a parameter to some method(s), and/or the return value from some method(s). In other words, the type exists only for documentation purposes, and you cannot call new declare.__DeclareCreatedObject()

Methods

createSubclass(mixins,props)

Defined by dojo/_base/declare

Create a subclass of the declared class from a list of base classes.

Create a constructor using a compact notation for inheritance and prototype extension.

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.

Parameter Type Description
mixins Function[]

Specifies a list of bases (the left-most one is the most deepest base).

props Object
Optional

An optional object whose properties are copied to the created prototype.

Returns: dojo/_base/declare.__DeclareCreatedObject

New constructor function.

Examples

Example 1

var A = declare(null, {
    m1: function(){},
    s1: "bar"
});
var B = declare(null, {
    m2: function(){},
    s2: "foo"
});
var C = declare(null, {
});
var D1 = A.createSubclass([B, C], {
    m1: function(){},
    d1: 42
});
var d1 = new D1();

// this is equivalent to:
var D2 = declare([A, B, C], {
    m1: function(){},
    d1: 42
});
var d2 = new D2();

extend(source)

Defined by dojo/_base/declare

Adds all properties and methods of source to constructor's prototype, making them available to all instances created with constructor. This method is specific to constructors created with declare().

Adds source properties to the constructor's prototype. It can override existing properties.

This method is similar to dojo.extend function, but it is specific to constructors produced by declare(). It is implemented using dojo.safeMixin, and it skips a constructor property, and properly decorates copied functions.

Parameter Type Description
source Object

Source object which properties are going to be copied to the constructor's prototype.

Examples

Example 1

var A = declare(null, {
    m1: function(){},
    s1: "Popokatepetl"
});
A.extend({
    m1: function(){},
    m2: function(){},
    f1: true,
    d1: 42
});

getInherited(name,args)

Defined by dojo/_base/declare

Returns a super method.

This method is a convenience method for "this.inherited()". It uses the same algorithm but instead of executing a super method, it returns it, or "undefined" if not found.

Parameter Type Description
name String
Optional

The optional method name. Should be the same as the caller's name. Usually "name" is specified in complex dynamic cases, when the calling method was dynamically added, undecorated by declare(), and it cannot be determined.

args Arguments

The caller supply this argument, which should be the original "arguments".

Returns: any | object

Returns a super method (Function) or "undefined".

Examples

Example 1

var B = declare(A, {
    method: function(a, b){
        var super = this.getInherited(arguments);
        // ...
        if(!super){
            console.log("there is no super method");
            return 0;
        }
        return super.apply(this, arguments);
    }
});

inherited(name,args,newArgs)

Defined by dojo/_base/declare

Calls a super method.

This method is used inside method of classes produced with declare() to call a super method (next in the chain). It is used for manually controlled chaining. Consider using the regular chaining, because it is faster. Use "this.inherited()" only in complex cases.

This method cannot me called from automatically chained constructors including the case of a special (legacy) constructor chaining. It cannot be called from chained methods.

If "this.inherited()" cannot find the next-in-chain method, it does nothing and returns "undefined". The last method in chain can be a default method implemented in Object, which will be called last.

If "name" is specified, it is assumed that the method that received "args" is the parent method for this call. It is looked up in the chain list and if it is found the next-in-chain method is called. If it is not found, the first-in-chain method is called.

If "name" is not specified, it will be derived from the calling method (using a methoid property "nom").

Parameter Type Description
name String
Optional

The optional method name. Should be the same as the caller's name. Usually "name" is specified in complex dynamic cases, when the calling method was dynamically added, undecorated by declare(), and it cannot be determined.

args Arguments

The caller supply this argument, which should be the original "arguments".

newArgs Object
Optional

If "true", the found function will be returned without executing it. If Array, it will be used to call a super method. Otherwise "args" will be used.

Returns: any | object

Whatever is returned by a super method, or a super method itself, if "true" was specified as newArgs.

Examples

Example 1

var B = declare(A, {
    method1: function(a, b, c){
        this.inherited(arguments);
    },
    method2: function(a, b){
        return this.inherited(arguments, [a + b]);
    }
});
// next method is not in the chain list because it is added
// manually after the class was created.
B.prototype.method3 = function(){
    console.log("This is a dynamically-added method.");
    this.inherited("method3", arguments);
};

Example 2

var B = declare(A, {
    method: function(a, b){
        var super = this.inherited(arguments, true);
        // ...
        if(!super){
            console.log("there is no super method");
            return 0;
        }
        return super.apply(this, arguments);
    }
});

isInstanceOf(cls)

Defined by dojo/_base/declare

Checks the inheritance chain to see if it is inherited from this class.

This method is used with instances of classes produced with declare() to determine of they support a certain interface or not. It models "instanceof" operator.

Parameter Type Description
cls Function

Class constructor.

Returns: any | object

"true", if this object is inherited from this class, "false" otherwise.

Examples

Example 1

var A = declare(null, {
    // constructor, properties, and methods go here
    // ...
});
var B = declare(null, {
    // constructor, properties, and methods go here
    // ...
});
var C = declare([A, B], {
    // constructor, properties, and methods go here
    // ...
});
var D = declare(A, {
    // constructor, properties, and methods go here
    // ...
});

var a = new A(), b = new B(), c = new C(), d = new D();

console.log(a.isInstanceOf(A)); // true
console.log(b.isInstanceOf(A)); // false
console.log(c.isInstanceOf(A)); // true
console.log(d.isInstanceOf(A)); // true

console.log(a.isInstanceOf(B)); // false
console.log(b.isInstanceOf(B)); // true
console.log(c.isInstanceOf(B)); // true
console.log(d.isInstanceOf(B)); // false

console.log(a.isInstanceOf(C)); // false
console.log(b.isInstanceOf(C)); // false
console.log(c.isInstanceOf(C)); // true
console.log(d.isInstanceOf(C)); // false

console.log(a.isInstanceOf(D)); // false
console.log(b.isInstanceOf(D)); // false
console.log(c.isInstanceOf(D)); // false
console.log(d.isInstanceOf(D)); // true

© 2005–2017 JS Foundation
Licensed under the AFL 2.1 and BSD 3-Clause licenses.
http://dojotoolkit.org/api/1.10/dojo/_base/declare.__DeclareCreatedObject.html