Question

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.
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
scroll top