-
-
Save adelura/d72870b378fcf64e91fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Button() { | |
this.open = function() { | |
// Developer decided that this event is semantically okay to be propagated. | |
this.fire( 'open', { propagate: true } ); | |
}; | |
} | |
Button.events = { open: 'open' }; | |
// This constructor implement a collection interface. | |
function Toolbar() {} | |
Toolbar.events = { open: 'open' }; | |
var toolbar = new Toolbar(); | |
// Here is a default - straightforward behaviour with on WTF. | |
// Fourth argument is not provided which means that only `open` events fired on toolbar will call a callback. | |
toolbar.on( Toolbar.events.open, function( e ) { | |
console.log( e.target instanceof Toolbar ); // Will always be `true`. | |
} ); | |
// Here we introduce a new, fourth parameter which filter out targets. | |
toolbar.on( Button.events.open, function( e ) { | |
console.log( e.target instanceof Button ); // Will always be `true`. | |
console.log( 'Hell, yeach button opened!' ); | |
}, toolbar, 1337, /* Filtered by target - */Button ); | |
toolbar.add( new Button() ); | |
toolbar.add( new Button() ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment