-
-
Save jorik041/5843947 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 invokee1 = function(err, callback) { | |
// cant change this function | |
callback(); | |
}; | |
var invokee2 = function(err, optional1, optional2, callback) { | |
// work with optional 1 or optional 2 | |
console.log(optional1); | |
console.log(optional2); | |
// cant change this function | |
callback(); | |
}; | |
var invoker = function(invokee) { | |
var cb = function() { | |
console.log('this is the callback'); | |
}; | |
// call the invokee with the right amount of arguments | |
var args = [null, 'a', 'b', 'c', 'd']; // null is the error arg | |
args[invokee.length - 1] = cb; | |
invokee.apply(null, args); | |
}; | |
invoker(invokee1); | |
invoker(invokee2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment