Created
March 4, 2014 16:41
-
-
Save jimmed/9350119 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 FBasync = {}; | |
// For each method in the FB library | |
_.each(FB, function(fn, name) { | |
// Create an equivalent method in FBasync | |
FBasync[name] = function() { | |
// Grab the arguments the function was called with | |
var _args = arguments; | |
return new Promise(function(reject, resolve) { | |
try { | |
// Call the function with our resolver as an additional argument | |
fn.apply(FB, Array.prototype.concat.apply(_args, [resolve])); | |
} catch(e) { | |
reject(e); | |
} | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment