Created
August 27, 2015 02:42
-
-
Save ericclemmons/b7937d863d29523936fc to your computer and use it in GitHub Desktop.
ES6 Classes as Factories
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
class HappyFactory { | |
constructor(message) { | |
return Promise.resolve(`${message} there!`); | |
} | |
} | |
new HappyFactory("Howdy").then(::console.log); | |
// "Howdy there!" |
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
"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