multifn
create functions with multiple overrides.
var multifn = ; var fn = ; ; // 1; // 4; // 5
install
node:
$ npm install multifn
browser:
$ bower install multifn
api
multifn()
Creates a new multifn. When the multifn is invoked, its if
functions will be invoked in the order they were specified, short circuiting when a matching if
function is found and returning the result of the corresponding do
function.
var fn = ; ; // 3; // 5
multifn().if(ifFn).do(doFn)
Defines a new override for the multifn. When ifFn
returns true
, doFn
will be invoked, its result used as the multifn's invokation result. Both ifFn
and doFn
will be invoked with the arguments that the multifn was invoked with, and will both have the multifn as their this
context.
var fn = ; // 5
multifn().else(elseFn)
Defines a new fallback function to use when none of the overrides match. Defaults to a 'noop': function() {}
.
var fn = ; ; // 1