Created
June 30, 2014 03:39
-
-
Save photofroggy/0225e7412f399ef15716 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
var callback = function( ) { | |
// Stuff you actually want to do. | |
}; | |
var afterFirst = function( callback ) { | |
// in-use callback | |
var cb = function( ) { | |
// Do nothing, set cb to callback | |
cb = callback; | |
}; | |
// Return a wrapper function so we're always calling cb | |
return function ( ) { | |
cb(); | |
}; | |
}; | |
var delegated = afterFirst( callback ); | |
// does nothing | |
delegated(); | |
// does something | |
delegated(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment