Skip to content

Instantly share code, notes, and snippets.

@ericclemmons
Created August 27, 2015 02:42
Show Gist options
  • Save ericclemmons/b7937d863d29523936fc to your computer and use it in GitHub Desktop.
Save ericclemmons/b7937d863d29523936fc to your computer and use it in GitHub Desktop.
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