Created
September 20, 2016 16:49
-
-
Save pragyandas/14e26b1e85c2b9c22606f378ebaf3ee8 to your computer and use it in GitHub Desktop.
partial application with promise created by pragyandas - https://repl.it/Ddl2/3
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
function bar(){ | |
var args=[].slice.call(arguments); | |
var cb=args[args.length-1]; | |
cb(null,"foo-bar"); | |
} | |
var mapper={ | |
foo:bar | |
} | |
function promisify(operator) { | |
return function() { | |
var args = [].slice.call(arguments); | |
return new Promise((resolve, reject)=>{ | |
mapper[operator].apply(null, args.concat([(err, result)=>{ | |
if (err) { | |
reject(err); | |
} else { | |
resolve(result); | |
} | |
}])); | |
}); | |
}; | |
} | |
var foo_promise=promisify("foo")(); | |
foo_promise.then((res)=>console.log(res)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment