3 ms·
We do something like classes in JavaScript without touching prototypes, and it works pretty well as a natural way of organizing and encapsulating code. Private
by brianpgordon 13y ago
We 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.