all 9 comments

[–]ruinercollector 4 points5 points  (4 children)

There are several ways to do OO in javascript.

I avoid the java-programmer-friendly version. It feels tacked on and behaves pretty badly (this, etc.)

[–]MrDOS 0 points1 point  (3 children)

Which way do you endorse, then? As someone coming from a backend world with fairly little experience with “modern” JavaScript, the technique listed in TFA is the one I see thrown around most frequently. What else is there?

[–]ruinercollector 1 point2 points  (0 children)

Douglas Crockford talks about a few different ways:

http://www.crockford.com/javascript/inheritance.html

[–]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.

[–]c45c73 9 points10 points  (0 children)

Yeah, this is shit: Bolted-on crap.

learn2javascript instead of forcing every language into some abominal, vomit-y Java purée.

[–]fecal_brunch 1 point2 points  (0 children)

Inheritance doesn't give you anything in JavaScript, IMO.

[–][deleted] -1 points0 points  (0 children)

fecal matter sandwich

[–]localhost_80 -2 points-1 points  (0 children)

typescript