API Documentation for: 1.0.0
Show:

Utility Methods Class

Defined in: Utility Methods:36
Module: CreateJS

Item Index

Methods

deprecate

(
  • [fallbackMethod=null]
  • [name=null]
)
Function

Defined in deprecate:40

Wraps deprecated methods so they still be used, but throw warnings to developers.

obj.deprecatedMethod = createjs.deprecate("Old Method Name", obj._fallbackMethod);

The recommended approach for deprecated properties is:

try {
    Obj    ect.defineProperties(object, {
        readyOnlyProp: { get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }) },
        readWriteProp: {
            get: createjs.deprecate("readOnlyProp", function() { return this.alternateProp; }),
            set: createjs.deprecate("readOnlyProp", function(val) { this.alternateProp = val; })
    });
} catch (e) {}

Parameters:

  • [fallbackMethod=null] Function optional

    A method to call when the deprecated method is used. See the example for how

  • [name=null] String optional

    The name of the method or property to display in the console warning. to deprecate properties.

Returns:

Function:

If a fallbackMethod is supplied, returns a closure that will call the fallback method after logging the warning in the console.

extend

(
  • subclass
  • superclass
)
Function

Defined in extend:40

Sets up the prototype chain and constructor property for a new class.

This should be called right after creating the class constructor.

function MySubClass() {}
createjs.extend(MySubClass, MySuperClass);
MySubClass.prototype.doSomething = function() { }

var foo = new MySubClass();
console.log(foo instanceof MySuperClass); // true
console.log(foo.prototype.constructor === MySubClass); // true

Parameters:

Returns:

Function:

Returns the subclass's new prototype.

indexOf

(
  • array
  • searchElement
)
Number

Defined in indexOf:40

Finds the first occurrence of a specified value searchElement in the passed in array, and returns the index of that value. Returns -1 if value is not found.

 var i = createjs.indexOf(myArray, myElementToFind);

Parameters:

  • array Array

    Array to search for searchElement

  • searchElement Object

    Element to find in array.

Returns:

Number:

The first index of searchElement in array.

promote

(
  • subclass
  • prefix
)
Function

Defined in promote:40

Promotes any methods on the super class that were overridden, by creating an alias in the format prefix_methodName. It is recommended to use the super class's name as the prefix. An alias to the super class's constructor is always added in the format prefix_constructor. This allows the subclass to call super class methods without using function.call, providing better performance.

For example, if MySubClass extends MySuperClass, and both define a draw method, then calling promote(MySubClass, "MySuperClass") would add a MySuperClass_constructor method to MySubClass and promote the draw method on MySuperClass to the prototype of MySubClass as MySuperClass_draw.

This should be called after the class's prototype is fully defined.

function ClassA(name) {
    this.name = name;
}
ClassA.prototype.greet = function() {
    return "Hello "+this.name;
}

function ClassB(name, punctuation) {
    this.ClassA_constructor(name);
    this.punctuation = punctuation;
}
createjs.extend(ClassB, ClassA);
ClassB.prototype.greet = function() {
    return this.ClassA_greet()+this.punctuation;
}
createjs.promote(ClassB, "ClassA");

var foo = new ClassB("World", "!?!");
console.log(foo.greet()); // Hello World!?!

Parameters:

  • subclass Function

    The class to promote super class methods on.

  • prefix String

    The prefix to add to the promoted method names. Usually the name of the superclass.

Returns:

Function:

Returns the subclass.