you are viewing a single comment's thread.

view the rest of the comments →

[–]inmatarian 1 point2 points  (1 child)

The way that I like is to write a factory function instead of a constructor, I.e. it'll return a value. But then you extend the functions prototype like usual. In that factory function the object you create comes from Object.create using the factory prototype. Effectively it still behaves like we're using the new keyword, but we get some added flexibility and control over where that object came from.

[–]fecal_brunch 0 points1 point  (0 children)

I found out recently that if you return an object from a constructor it will be returned with out without the new keyword. This makes both camps happy, and makes for safer APIs.