Skip to content

Instantly share code, notes, and snippets.

@photofroggy
Created June 30, 2014 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save photofroggy/0225e7412f399ef15716 to your computer and use it in GitHub Desktop.
Save photofroggy/0225e7412f399ef15716 to your computer and use it in GitHub Desktop.
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