Hacker News new | past | comments | ask | show | jobs | submit login

JavaScript is object oriented just like any other language. The difference is that it is prototype-based OO instead of class-based OO.

I would say that JavaScript's OO is actually more powerful/flexible than other languages but it is less readable and more error prone if you're not careful - For example, the fact that objects can 'borrow' a method from other object an apply it to themselves is a common source of issues for beginners.




It's possible to get power without flexibility. Flexibility is bad -- it creates code that is idiomatic to the person who wrote it.

Rust and Go are so exciting because they've intentionally rejected flexibility without compromising power.


Flexibility is not 'bad' - it's a tradeoff. More flexible languages are better for writing DSLs, etc; but using them means a lot of self discipline regarding code style.

One thing I wish JS had is a PEP8-style canonical style document. I would find that more useful than classes.

On classes, I am among the less excited about them; however, we are in a ridiculous situation where there are about 500 different library implementations of class inheritance. Backbone has one. Ember has one. Node has util.inherits. Various transpile-to-JS languages (CS, TS) all have their own slightly-different implementations of the resulting prototype code. There is plainly a need for classes in JS, felt by some of the leading projects in JS land.

ES6 classes at least gives all these disparate implementations a refactoring target. How many of them will get there is another matter.


> More flexible languages are better for writing DSLs, etc;

Citation needed, or, I'm not quite sure I agree with you there. In fact, I think I believe the exact opposite (to a degree).


> using them means a lot of self discipline regarding code style.

That's bad. Few developers have self-discipline. The ones who do still have different rules than you do. That makes reading, understanding, and modifying their code harder. Sounds bad, doesn't it?

There's a reason the most experienced devs rage against extremely flexible languages like PHP and JavaScript and are excited about new, ultra-rigid languages.


A lot of other languages makes you write a lot more code for some things that js can express very shortly. I usually find that the js version is more readable. The problem, I think, is that most programmers are used to class-based inheritance and not prototypical inheritance.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: