Created
April 9, 2010 20:06
-
-
Save cowboy/361531 to your computer and use it in GitHub Desktop.
Triggering bound event handlers
This file contains hidden or 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
// The jQuery way. | |
$(elem).bind( 'foo.bar', function(event){ | |
do_something( event.target ); | |
}).triggerHandler( 'foo.bar' ); | |
// The old-school silly way. | |
function fn( event ){ | |
do_something( event.target ); | |
}; | |
$(elem).bind( 'foo.bar', fn ); | |
fn( $.Event('click') ); | |
// The new school silly way. | |
$(elem).bind( 'foo.bar', (function fn(event){ | |
do_something( event.target ); | |
return fn; | |
})( $.Event('click') )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment