Last active
September 20, 2016 16:34
-
-
Save branneman/ca4eaa8fc6e4bb3a20b7b8fc680ad8e0 to your computer and use it in GitHub Desktop.
ES2015: Returning a Promise from a constructor — Warning: I'm fairly sure this is always an anti-pattern.
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 Parent { | |
constructor() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve({ data: 'important' }), 1e3); | |
}); | |
} | |
} | |
class Child extends Parent { | |
constructor() { | |
return super().then(console.log); | |
} | |
} | |
( new Parent() ).then(console.log); | |
//=> { data: 'important' } | |
( new Child() ); | |
//=> { data: 'important' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment