OO.Factory()

Show:

new Factory()

...

Extends

Methods

create(key, …argsopt) → {Object}

Create an object based on a key.

Create an object based on a key.

The key is used to look up the class to use, with any subsequent arguments passed to the constructor function.

Parameters:
Name Type Attributes Description
key string

Class key

args any <optional>
<repeatable>

Arguments to pass to the constructor

Source:
Throws:

Unknown key

Type
Error
Returns:

The new object

Type
Object

lookup(name) → {any|undefined}

Get data for a given symbolic name.

Get data for a given symbolic name.

Parameters:
Name Type Description
name string

Symbolic name

Inherited From:
Source:
Returns:

Data associated with symbolic name

Type
any | undefined

register(constructor, keyopt)

Register a class with the factory.

Register a class with the factory.

function MyClass() {};
OO.initClass( MyClass );
MyClass.key = 'hello';

// Register class with the factory
factory.register( MyClass );

// Instantiate a class based on its registered key (also known as a "symbolic name")
factory.create( 'hello' );
Parameters:
Name Type Attributes Description
constructor function

Class to use when creating an object

key string <optional>

The key for #create(). This parameter is usually omitted in favour of letting the class declare its own key, through MyClass.key. For backwards-compatiblity with OOjs 6.0 (2021) and older, it can also be declared via MyClass.static.name.

Overrides:
Source:
Throws:

If a parameter is invalid

Type
Error

unregister(key)

Unregister a class from the factory.

Unregister a class from the factory.

Parameters:
Name Type Description
key string | function

Constructor function or key to unregister

Overrides:
Source:
Throws:

If a parameter is invalid

Type
Error

Events

register

...
Parameters:
Name Type Description
name string
data any
Inherited From:
Source:

unregister

...
Parameters:
Name Type Description
name string
data any

Data removed from registry

Inherited From:
Source: