Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Forked from barneycarroll/multi.js
Created March 23, 2016 23:43
Show Gist options
  • Save Bondifrench/3e13e96b7008b5e2efdc to your computer and use it in GitHub Desktop.
Save Bondifrench/3e13e96b7008b5e2efdc 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 )
}
}
@Bondifrench
Copy link
Author

ex:

m('button', {
  onclick: function(event) {
    onclick1(event)
    onclick2(event)
  }
}, 'label')

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