JavaScript ES6 is Doing Too Much

Swiss Army Knife

This is a Swiss Army Knife. The Handyman, to be precise. According to the site, it has 24 functions. Can opener, scissors, nail file, pliers, wine opener, bottle opener, wood saw, toothpick, nail cleaner … the list goes on.

Conceptually, it’s really great to have one thing that does so much.

Realistically, Swiss Army Knives have not replaced the need for single-purpose devices in any of those categories.

It’s doing too much to be good enough at one task to replace a device crafted specifically to solve a single purpose in any of those categories.

I fear ES6 is introducing tools that make JavaScript do too much.

 

Let me give a tangible example. We’ve heard JavaScript is a language where functions are first-class objects.

This is really a fancy way of saying functions can be treated like any other data type. Just like you can take a number, string, array or object and store it in a variable, pass it as an argument to a function or return it as a result of processing a function,  you can do the same with a function.

This means functions are very important in JavaScript. Using them properly is a Major Key to Success.

How do you create a function Pre-ES6?

// 1. NAMED FUNCTION
  function shout( msg ){
    alert( msg.toUpperCase() );
  }

// 2. ANONYMOUS FUNCTION
  var shout = function( msg ){
    alert( msg.toUpperCase() );
  }

// 3. FUNCTION "CLASS" 
  var shout = new Function('msg', 'alert( msg.toUpperCase() );');

To be honest, nobody really uses the third method so you can pretty much ignore it. Which leaves method one and two as the only practical candidates.

Named and Anonymous Functions are syntactically identical. The difference is while one creates a function called shout, the other creates an unnamed function and stores it in a variable named shout. The way to create them is identical. There’s no mistaking a function declaration when you see it.

How do you create a function in ES6?

https://gist.github.com/paulrouget/5262478

Yup you’re seeing correctly. In addition to the original three two ways (which the creator of that gist boiled down to one way because they were practically the same thing), there’s an additional 3 official ways to do the exact same thing!

This comment on the gist pretty much summarizes my thoughts on the matter.

Having multiple options to write the same thing will only decrease readability.
Instead of spending 2 seconds to write the “function()” string, you will spend more time to read code, on the long run.

So, I’m not happy at all about the new ES6 syntax.

– andreipfeiffer

 

I get that the compact new way of writing functions is attractive to very experienced programmers, but I don’t think pros are what made JavaScript the popular language it is.

People who knew C or Java, who had a familiarity with JavaScript’s “C-like Syntax,” had nothing to do with JavaScript’s success. At the time the web saw its first boom these programmers were still betting on Java and .NET. JavaScript succeeded because it made what those programmers did accessible to people without their background, not those with a background similar to their own.

– Mikeal Rogers

ES6 is an attempt to make JavaScript look like other programming languages. For all the other advantages those languages have over it, those languages are harder to learn and they are way less approachable. ES6 is turning JavaScript into a more complicated language with arguably dubious benefits. After all, virtually nothing it brings to the table was previously impossible in the first place.

ES6 is making JavaScript more complicated to appeal to people who program in more complicated languages and I think this is a terrible decision.