#

API Documentation for: 0.8.1
Show: Inherited Protected Private Deprecated

# Utility Methods Class

Defined in: `Utility Methods:36`
Module: CreateJS

- Index
- Methods

## Item Index

### Methods

- extend
- indexOf
- promote

## Methods

### `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:

- `subclass` Function

  The subclass.

- `superclass` Function

  The superclass to extend.

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