Extends
Methods
create(key, […args]) → {Object}
#
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:
Returns:
The new object
- Type
- Object
Throws:
-
Unknown key
- Type
- Error
lookup(name) → {any|undefined
}
#
undefined
}
#
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, [key])
#
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 |
- Overrides:
- Source:
Throws:
-
If a parameter is invalid
- Type
- Error
unregister(key)
#
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(name, data)
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | |
data |
any |
- Inherited from:
- Source:
unregister(name, data)
#
Parameters:
Name | Type | Description |
---|---|---|
name |
string | |
data |
any | Data removed from registry |
- Inherited from:
- Source: