Function
Methods
bind(thisArg) → {function}
Creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
Parameters:
Name Type Description thisArg function The value to be passed as the this parameter to the target function when the bound function is called.
Returns:
The bound function.
bindTo() → {function}
Alias for function.bind.
Returns:
The bound function.
defer() → {Number}
Alias for function.delay.
Returns:
The numerical ID of the timeout.
delay(delay, thisArg, args) → {Number}
Delays execution of the function by the given delay.
Parameters:
Name Type Description delay Number Time to delay in milliseconds.
thisArg Object Object to use for this when calling the function.
args Array Arguments to use when calling the function.
Returns:
The numerical timeout ID of the delayed function.
pass(arg, thisArg) → {function}
Creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called.
Parameters:
Name Type Argument Default Description arg Array optional [] Arguments to prepend to the bound function.
thisArg Object The value to be passed as the this parameter to the target function when the bound function is called.
Returns:
The newly bound function.
periodical(periodical, scope, args) → {Number}
Periodically call the function with the given scope and arguments.
Parameters:
Name Type Description periodical Number Number of milliseconds to wait before each call to function.
scope Object Scope to use when invoking function.
args Array Arguments to use when calling the function.
Returns:
The numerical ID of the interval.
subscribeOnce(publisher, eventTypes, scope) → {function}
Subscribes a method to a list of events. Each event subscribed will only be fired once, after which it is unsubscribed.
Parameters:
Name Type Argument Description publisher Class Object or Class on which you want to register the method.
eventTypes String | Array String or array containing eventTypes to which to subscribe this method to.
scope Object optional Scope in which the method will run when the event fires.
Returns:
Method as subscribed.
subscribeTo(publisher, eventTypes, scope) → {function}
Subscribes a method to a list of events
Parameters:
Name Type Argument Description publisher Class Object or Class on which you want to register the method.
eventTypes String | Array String or array containing eventTypes to which to subscribe this method to.
scope Object optional Scope in which the method will run when the event fires.
Returns:
Method as subscribed.
unsubscribeFrom(publisher, eventTypes) → {function}
Unsubscribes a method from a list of events
Parameters:
Name Type Description publisher Class Object or Class on which you want to unregister the method.
eventTypes String | Array String or array containing eventTypes from which to unsubscribe this method to.
Returns:
Method as unsubscribed.
Example
var differentScope = new new MAF.Class({ // Create and initialize a new MAF.Class in one go. version: 123 }); var publisher = new new MAF.Class({ // Create and initialize a new MAF.Class in one go. version: 321 }); var fnOriginal = function (ev) { switch (ev.type) { case 'withScope': console.log('Running in differentScope scope, version: ', this.version); break; case 'noScope': console.log('Running in publisher scope, version: ', this.version); break; } }; //If you subscribed with using a scope, you have to unsubscribe using the returned method. var fnSubscribed = fnOriginal.subscribeTo(publisher, ['withScope'], differentScope); fnOriginal.subscribeTo(publisher, ['noScope']); publisher.fire('withScope'); publisher.fire('noScope'); fnSubscribed.unsubscribeFrom(publisher, ['withScope']); fnOriginal.unsubscribeFrom(publisher, ['noScope']);