Skip to content

Instantly share code, notes, and snippets.

@naholyr
Last active August 29, 2015 13:57
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 naholyr/9828826 to your computer and use it in GitHub Desktop.
Save naholyr/9828826 to your computer and use it in GitHub Desktop.
function wrap (fn, args, thisArg) {
return function () {
return Promise(function (resolve, reject) {
fn.apply(thisArg, (args || []).concat([function (err, res) {
if (err) reject(err)
else resolve(res)
}]))
})
}
}
function ninvoke (method, args) {
return function (o) {
return wrap(o[method], args, o)
}
}
promiseOfObject.then(ninvoke('method', [x, y]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment