Constructor
new Model(nameopt)
Creates an instance of a Model.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
name |
String |
<optional> |
--unnamed model-- | A name for the model |
Members
name :String
The name of the model.
Type:
- String
observers
The set of observer functions to be called when this Model is changed
via set() method.
Methods
addObserver(observer)
Adds an observer function to this Model.
Parameters:
Name | Type | Description |
---|---|---|
observer |
function | The observer to add. |
- Source:
- See:
notifyObservers(hintopt)
Invokes all observers.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
hint |
Object |
<optional> |
An optional object to pass as argument to observers. |
removeObserver(observer)
Removes an observer function from this Model.
The function will no longer be notified of changes in this Model.
The function will no longer be notified of changes in this Model.
Parameters:
Name | Type | Description |
---|---|---|
observer |
function | The observer to be removed. |
set(updater, hintopt)
Method to update the this Model.
A callback function is passed which is, typically, in charge to make changes in this object. When this callback returns, observers of this Model are notified.
A callback function is passed which is, typically, in charge to make changes in this object. When this callback returns, observers of this Model are notified.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
updater |
function | The callback function in charge of changing this Model. The function will receive the reference to this Model as parameter. | |
hint |
Object |
<optional> |
Any additional object to be passed to observers during notification. |
Example
Model m = new Model('mymodel');
m.set( () => { m.itemName='Tablet'; m.price=1200});