OO.Factory()

Show:

new Factory()

...

Extends

Methods

create(name, …argsopt) → {Object}

Create an object based on a name.

Create an object based on a name.

Name is used to look up the constructor to use, while all additional arguments are passed to the constructor directly, so leaving one out will pass an undefined to the constructor.

Parameters:
Name Type Attributes Description
name string

Object name

args any <optional>
<repeatable>

Arguments to pass to the constructor

Source:
Throws:

Unknown object name

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, nameopt)

Register a constructor with the factory.

Register a constructor with the factory.

function MyClass() {};
OO.initClass( MyClass );
MyClass.static.name = 'hello';
// Register class with the factory, available via the symbolic name "hello"
factory.register( MyClass );
Parameters:
Name Type Attributes Description
constructor function

Constructor to use when creating object

name string <optional>

Symbolic name to use for #create(). This parameter may be omitted in favour of letting the constructor decide its own name, through constructor.static.name.

Overrides:
Source:
Throws:

If a parameter is invalid

Type
Error

unregister(name)

Unregister a constructor from the factory.

Unregister a constructor from the factory.

Parameters:
Name Type Description
name string | function

Constructor function or symbolic name 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: