
Introduction to Object-Oriented JavaScript - Garbage
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Introduction_to_Object-Oriented_JavaScript
======
Matachines
JS isn't OOP and it doesn't need to be. Please read this instead:

[https://medium.com/javascript-scene/the-two-pillars-of-
javas...](https://medium.com/javascript-scene/the-two-pillars-of-javascript-
ee6f3281e7f3)

~~~
hughw
I agree. JS is beautiful in the parts where it encourages functional, not
object, programming. That link puts it nicely: "You're working in the phony
version of JavaScript that only exists to dress the language up like Java." In
the Mozilla article, I can hardly believe I'm reading discredited perennials
like "OOP promotes greater flexibility and maintainability in programming ...
Because OOP strongly emphasizes modularity, object-oriented code is simpler to
develop and easier to understand later on." That was the promise, in 1985. The
reality is, OOP has created a snarl of programs where mutable state is the
defining characteristic, justified by a consulting industry that is more
promotion than real, grounded theory. They live on.

~~~
oldmanjay
You're vastly overstating what you consider the "reality" of object oriented
programming. Systems designed to be OO from the beginning are clearly
massively successful at producing incredibly complicated software. The
paradigm has not been discredited despite your assertion or your personal idea
of beauty.

~~~
hughw
Nice try, Grady.

(edit... y'all, please let me have a little joke)

~~~
hughw
Nope, I knew there'd be a regular humorless hn down voting dickhead. Oh right,
I'm not supposed to mention that, or I'll get more dread down votes lol.

------
kremlin
This is just in time. I just read a chapter in a JavaScript book about OO
programming in JS and finished the chapter very confused. It demonstrated
about 12 different patterns people have used for creating 'classes' and
'subclassing' them, each with a list of advantages and disadvantages.

Eg there's the 'parasitic instantiation' and then there's the 'Constructor
pattern' and then there's the 'Parasitic Constructor', and there's like 3
other patterns that have their own permutations. Coming from Python and then
Java, where classes just work...it's kind of annoying.

[edit] I was being a bit hyperbolic, the book discussed 6 ways of inheritance
in JS, those being (1) Prototype Chaining (2) Constructor Stealing (3)
Combination Inheritance <\- most popular one according to the book (4)
Prototypal Inheritance (5) Parasitic Inheritance (6) Parasitic Combination
Inheritance <\- pattern that is generally the best according to the book

~~~
woah
Inheritance is rarely necessary

------
cnp
When will people start releasing ES6 editions of things? Seems so old school
when you can simply write

`class Foo extends Bar {}`

~~~
bkurtz13
Now you're being old school. It's called ES2015 now! ;)

(edit: app I was using chopped my comment...)

~~~
cnp
True true, though it's more characters to type :) And is ES7 going to be
called ES2016? (Considering how JavaScript is starting to run everything there
is a certain long-term logic to this naming approach.)

~~~
thomasfoster96
ES7 is still ES7, and ES8 is still ES8. I'm not even convinced ES6 got renamed
- nowhere apart from HN comments have I seen it called ES2015.

------
thomasfoster96
I'm still worried that the idea of a namespace is still being thrown around in
JavaScript. If you've used PHP (which presumably quite a few inexperienced
programmers might have before they get into JavaScript), JavaScript namespaces
act nothing like PHP namespaces. A JavaScript namespace is just a global
variable. Nothing fancy.

------
ExpiredLink
But why? JavaScript obviously wasn't made with object-orientation in mind.

~~~
stesch
That's why every framework invents its own kind of OO for it. :-(

------
bbcbasic
> Or we can set this explicitly using Function#call (or Function#apply), as
> shown at the end of the example.

Or we can define a variable self in the class, set self = this in the
constructor, and refer or that hereon.

------
hoare
Wouldnt the only thing that js need to be fully oo be a proper inheritence?
Prototyping has its advantages too though

~~~
sup
That's coming in es6

~~~
oldmanjay
I know people are crying out for this, but I can only shudder inside at the
unholy mudball messes that will result. Inheritance is one of those things we
shouldn't let anyone use until they're 40 or so.

~~~
leonatan
Or, with great power comes great responsibility, and we shouldn't let
uneducated and untrained quick-buck "developers" work on our software.

~~~
oldmanjay
Well to be fair to myself, I was mainly making a joke. But the simple truth is
that inheritance doesn't bring new power to the table, just syntax sugar, and
with great sugar comes diabetes and painful death.

~~~
EugeneOZ
Classes is a big enough portion of sugar to change expression level of code.
After writing ES6 few months I don't like to write ES5 again, when I have to,
and there is a lot of people who think so. Arrow functions is the another (if
not first) big thing which makes this feeling stronger, and it's just a syntax
sugar also. OO in ES5 looks less readable and less.. "native" than in ES6.
Hope in some ES version 'this' insanity will be fixed and all will be just
fine with classes.

just for note: I have never used "extends" in ES6.

