Skip to content

Instantly share code, notes, and snippets.

@jimmed
Created March 4, 2014 16:41
Show Gist options
  • Save jimmed/9350119 to your computer and use it in GitHub Desktop.
Save jimmed/9350119 to your computer and use it in GitHub Desktop.
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