Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES6 Classes as Factories
class HappyFactory {
constructor(message) {
return Promise.resolve(`${message} there!`);
}
}
new HappyFactory("Howdy").then(::console.log);
// "Howdy there!"
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var HappyFactory = function HappyFactory(message) {
_classCallCheck(this, HappyFactory);
return Promise.resolve(message + " there!");
};
new HappyFactory("Howdy").then(console.log.bind(console));
// "Howdy there!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment