Skip to content

Instantly share code, notes, and snippets.

@barneycarroll
Last active March 23, 2016 23:43
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save barneycarroll/6671463fbe593b2bd8a8 to your computer and use it in GitHub Desktop.
Save barneycarroll/6671463fbe593b2bd8a8 to your computer and use it in GitHub Desktop.
Execute multiple functions where one is expected. Useful for event handling.
function multi(){
var handlers = Array.prototype.filter.call( arguments, function( x ){
return x instanceof Function
} )
return function handle(){
for( var i = 0; i < handlers.length; i++ )
handlers[ i ].apply( this, arguments )
}
}
@pelonpelon
Copy link

Use case:

m( 'form', {
    onkeypress : multi(
        onKey( 'enter', ctrl.save ),
        onKey( 'esc',   ctrl.delete )
    )
}, content );

onKey function here

@gilbert
Copy link

gilbert commented Apr 29, 2015

An alternative name for this function is doAll

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment