new OO.Factory()
#
Hierarchy
- Source:
Extends
Methods
create(key, …argsopt) → {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:
Throws:
-
Unknown key
- Type
- Error
Returns:
The new object
- Type
- Object
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, keyopt)
#
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 |
- 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: