3 ms·
Javascript is fundamentally an object-oriented language, it's just prototype-based rather than class-based.
by cwp 13y ago
Javascript is fundamentally an object-oriented language, it's just prototype-based rather than class-based.
- SideburnsOfDoom 13y agoIt seems more like a functional language to me, but YMMV: http://stackoverflow.com/a/501053/5599 http://stackoverflow.com/a/501053/5599
- kazagistar 13y agoYou seem to be under the impression that those are somehow mutually exclusive.
- SideburnsOfDoom 13y agoI'm sorry if you though so. I am not under that impression. However as mentioned elsewhere ( https://news.ycombinator.com/item?id=7500280 https://news.ycombinator.com/item?id=7500280 ) if most of what you do to organise your code involves passing functions to functions and very little of it involves creating class hierarchies or prototype chains, it's a fair assessment that the language that you are using is more functional than OO. The language that you are using may be a subset of the whole language, but with JavaScript that's given - you have to find the good parts or go mad trying. I was wrong about JavaScript as a whole, but maybe less so about JavaScript as it is successfully used.
- brianpgordon 13y agoWe do something like classes in JavaScript without touching prototypes, and it works pretty well as a natural way of organizing and encapsulating code. Private members are variables/functions defined within the constructor's closure. Public members are properties added to "this" by the constructor. Mixins can be done by calling another class's constructor on yourself. The point is that class-based OO can be trivially imposed on JavaScript objects without abandoning the native object construction mechanism like ember.js does. In fact, CoffeeScript does this in order to implement its own classes.