DEV Community

Discussion on: The Proper Way to Write Async Constructors in JavaScript

 
darlanalves profile image
Darlan Alves

Cool trick indeed!

You could define one factory by convention, e.g. await Spotify.create(code) and apply in your codebase.

I'd prefer that to "fetchUser", because you will need more static methods if you want to add behavior.

A single entry point for a class, and then you can have as mathods as necessary.

Thread Thread
 
somedood profile image
Basti Ortiz

I totally agree! This is actually how it's done in the Rust ecosystem. Though, instead of create, the typical naming convention is new. But create also conveys the same semantics! 👌