-1

As a budding software engineer, what is worth time-investment in terms of Javascript? I'm interested in long term payoffs in terms of a deeper understanding of languages, tech, software engineering, etc. over just using languages.

I really like JavaScript's prototype model and am perfectly comfortable implementing object inheritance, closure, etc. and would consider myself a midlevel-to-advanced user. There is plenty I'm still unaware of, however, including how Promise constructors work, generators/iterators and probably more. I've also become aware of how you can implement functional patterns in Javascript, something I would be interested in becoming comfortable with going forward. (it seems like you can't easily use a 'class' based syntax with functional coding).

But Javascript as a prototype language is becoming masked by ES6/Typescript/etc. These syntactical-sugar implementations seem likely to become more prevalent than Javascript itself.

I'm looking for opinions from developers more experienced than myself on what direction to choose in developing a new app that I'm about to start regarding honing an existing (possibly outdated) skill or developing a new, more modern skill.

My choices are:

  1. Carry on deeper into the Javascript prototype model
  2. Implement (and learn) the new ES6 class-based syntax.
5

If you're talking about a learning exercise, then I think it's very useful in the long run to fully understand how Javascript's prototype model works under the covers and the best way to do that is to run through a bunch of exercises building object hierarchies without the ES6 syntax sugar. If you can do subclassing and mixins using plain prototypes and fully understand how those combined objects are built and work using plain ES5 Javascript, then you will have a very good understanding of how the core parts of the prototype system works.

Once you have that understanding, then feel free to use the ES6 class syntax to express your desired structure because it's just plain simpler to read and write. But, you are correct that the new syntax hides a fair amount of the actual implementation which will also obscure how it really works under the covers. So, I'd say to learn how to do it the old-fashioned way without the new syntactic sugar and then when you go to actually write code using the ES6 syntax, you will better know what it's actually doing under the covers.

The new ES6 syntax is still just sugar over the prototype model so there is no either/or. If you don't learn the prototype model first, you won't really understand what the ES6 class syntax is actually doing. And, then when you want to debug something complex or you want to do something that doesn't have new syntax for (such as built a mixin object), you won't really understand how it all works underneath. I'd vote for learning the basic prototype model first and then after you've done that, use the new syntax as a cleaner way to express the desired structure.

My choices are:

Carry on deeper into the Javascript prototype model

Yes, do this first.

Implement (and learn) the new ES6 class-based syntax

Then, after doing the first, write your production code using the new syntax, but with a full understanding of what it's actually doing under the covers.


As a nice little test exercise, declare two separate classes with the ES6 syntax. Subclass each one. Then, create a new mixin object that is a mixin of both your subclassed objects. If you can do that, then you probably understand how the ES6 syntax actually uses the prototype.

  • 1
    Unless ES6 transpilers are a leaky abstraction, I'm having trouble understanding why one would be compelled to learn prototypal inheritance first. Sure, it's always better to know how it works under the covers, but only as an intellectual exercise, if ES6 is well-designed. – Robert Harvey Nov 1 '16 at 23:27
  • 1
    @RobertHarvey - It's not only an intellectual exercise to know how it works underneath. It helps you design better code, it helps you debug things when things are wrong. It helps you understand legacy code you may use from other modules. And, it helps you implement occasionally useful things that are not directly supported with new syntax such as mixins. This is no different than you're a more powerful C++ developer if you actually have some idea how an object is structured in memory when you declare a class, a subclass and use virtual methods. – jfriend00 Nov 1 '16 at 23:33
  • Of course. But it's certainly not a requirement. – Robert Harvey Nov 1 '16 at 23:59
  • @RobertHarvey - ES6 can be well designed, but it's not complete. You can't do everything you may want to do to the construction of objects without ever understanding the prototype. And, you can't understand certain types of problems/bugs without understanding the prototype. And, you can't understand how to optimize certain parameters (performance, memory use, etc..) without understanding the prototype. It's very useful to know how it works under the covers and the best and most senior and most capable JS developers will understand how the prototype works. – jfriend00 Nov 2 '16 at 0:09
  • So, leaky abstraction then. – Robert Harvey Nov 2 '16 at 0:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.