Skip to content

Instantly share code, notes, and snippets.

@venil7
Last active August 29, 2015 13:59
Show Gist options
  • Save venil7/10770587 to your computer and use it in GitHub Desktop.
Save venil7/10770587 to your computer and use it in GitHub Desktop.
require.js meets ES6 Promises
var required = function(name) {
name = name.toString();
return new Promise(function(resolve, reject) {
require([name], function(module) {
resolve(module);
},
function(err){
reject(err);
});
});
};
//usage
required("./test")
.then(console.log.bind(console, "success:"))
.catch(console.log.bind(console, "error:"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment