2 ms·
If you're trying to say that OOP isn't the central organizing principle of JavaScript, then I 100% agree with you. Lambdas and closures are awesome. However, J
by erikpukinskis 12y ago
If you're trying to say that OOP isn't the central organizing principle of JavaScript, then I 100% agree with you. Lambdas and closures are awesome.
However, JavaScript does have the "new" keyword, and I would argue that constructors are quite central to JavaScript and good idiomatic JavaScript uses them. And it exposes YourConstructor.prototype, which I would argue is also useful.
So I guess maybe you're saying something about the term OOP that I don't understand. Maybe OOP means "everything is an object" to you? Or it means multiple inheritance?
I guess I don't understand the distinction you're trying to draw when you say "not OOP".
- EugeneOZ 12y agoArticle of the same author, on the related subject: https://medium.com/javascript-scene/how-to-fix-the-es6-class-keyword-2d42bb3f4caf https://medium.com/javascript-scene/how-to-fix-the-es6-class...
- zachrose 12y agoThere's a whole depth of abstractions that people imply when they talk about OOP in JavaScript. In my mind they go something like this. 1) Using object literals for values. 2) Using object literals with functions. 3) Using object literals with functions and calling them in contexts (`this`, `bind`, `apply`). 4) Using the `new` keyword. 5) Designing objects with inheritance hierarchies or prototype chains. 6) Designing mutable and stateful objects with indefinite life spans. I don't understand the arguments that classical-ish inheritance in JS is bad while prototypical inheritance is somehow better. I've worked in codebases that liberally extend objects into different types of objects with long prototype chains, and IMHO they suffered from the same problems that people complain about in classical inheritance: tight coupling, premature/wrong abstractions, gradual violations of open/closed, etc. Personally, I go through 1-4 liberally and 5 and 6 conservatively. IMHO, complaints about inheritance mechanisms seem to have something in common with the people who talk about the special needs of "large-scale applications". Why not just make smaller apps, or make smaller things that compose with less knowledge of where they are? NB: It's entirely possible that I haven't run into the kind of complex requirements where liberal inheritance is a good fit. I'd be interested in hearing stories about when that worked out well.
- grayrest 12y ago> Why not just make smaller apps, or make smaller things that compose with less knowledge of where they are? The easy answer to this is that successful apps have a tendency to grow larger than expected and splitting them up requires care and lots of work. Class based inheritance provides a familiar way to split up the state space via encapsulation. It provides some boundaries instead of none and theoretically allows you to separate out your concerns and not have to think about the system-wide implications when writing code in your class. I'm in the functional camp and think classes aren't a great way to build software but I support the addition of `class` to ES6 since it shifts the ecosystem from a hundred slightly-incompatible versions to a single one. The mystery to me is why the people who advocate for JS classes are still writing JS rather than writing Typescript or Dart to further constrain their state space with a type system.
- deleted 12y ago[deleted]