Hacker News new | past | comments | ask | show | jobs | submit login
ECMAScript 6: new OOP features besides classes (2ality.com)
87 points by StylifyYourBlog on Dec 29, 2014 | hide | past | favorite | 33 comments



First we have to wait for complete implementations.

Then wait for v8 performance: http://jsperf.com/performance-frozen-object ES5 is doing good...

And at last: Wait for < IE-11 to die.

It remains to be seen if io.js will boosts ES Next for the server. Since bound to v8 i don't expect much.

Other implementations like the ahead of time compiler echojs become interesting. I am also curious how Typescript will look at v2.0.

I am ready, however I still don't use arrow functions... Which were first heard of in 2010? 2011?

It still feels like so far away.


You are absolutely right when it comes to using ECMAScript 6 natively. It will officially become a standard in mid 2015. By then modern browsers should have implemented most of it, but it will be years until legacy browsers go away. It feels to me that (for most projects) we can just now rely on ECMAScript 5 being there everywhere.

On the other hand, there are already a few decent solutions for transpiling ECMAScript 6 to ES5 [1]:

* Traceur (there are Traceur-based plugins for Grunt, Gulp, browserify, webpack, etc.): https://github.com/google/traceur-compiler

* 6to5: https://6to5.org/

* es6-transpiler.js: https://github.com/termi/es6-transpiler

Using those tools results in a workflow that is much like using CoffeeScript.

[1] http://www.2ality.com/2014/08/es6-today.html


I am mostly looking forward to Proxies and Tail calls, both cannot be implemented with traceur :/


Having a standard for classes would be significant even if no browser implemented it.

Nearly every JavaScript ecosystem has a class pattern. Ember, Angular, YUI, React, MooTools etc. All of them are incompatible.

A spec gives us a common target to iterate toward, even if we need to get there via transpilers. Just like standardizing on Promises means I can consume jQuery's ajax method without learning a new callback syntax, ES6 classes will mean I don't need to learn a new API for extending a parent class in every framework.

The Ember community has had amazing success adopting ES6 modules despite there being no browser support at all. I expect any framework would have a similar success story with classes.


Standardizing is also the reason behind ES7 Observable as was explained in this talk (https://www.youtube.com/watch?v=DqMFX91ToLw) from Jafar Husain (Netflix & ES7 committee) which explains very well ES6/ES7 features like iterators, promises, generators, async functions and async generators.


We don't have to wait to use these features, we can use them today with Traceur, 6to5, ES6ify, etc.


I guess the guy that proposed an '====' operator lost to the guy that proposed a 'Object.is()' method.


I'm sorry most of the sugar I don't find particularly helpful and can be confusing when you have more than one way to do something. generators, async keyword these should be prioritized not class based inheritance. Even block scoping I mean maybe I'm nuts but function scoping if you take the time to understand it, it works.


>generators, async keyword these should be prioritized not class based inheritance

Generators are indeed being prioritized over classes and inheritance; the former is starting to see support in browsers but there's no sign of the latter.

The async-await keywords are not in ES6, but they are trivial to mimic with generators and promises if you so desire.

>Even block scoping I mean maybe I'm nuts but function scoping if you take the time to understand it, it works.

Block scoping introduces no new pitfalls (unless you count learning two new keywords a pitfall). It does however eliminate two classes of bugs - redeclaring a var with the intent of shadowing the previous one but actually overwriting it, and using a var outside of a scope where it has a legal value. I'd say it's worth it.


Classes are in IE11 Technical Preview and, I believe, the latest versions of V8 as well.


Ah, you're right. Chrome Dev has support for classes now. Good to know!


Javascript books get bigger, "The Good Parts" stays the same.


I'd say fat-arrow lambdas and multiple variable assignments are good... a lot of the other stuff, don't care as much... though generators/promises leading to await/async is pretty good too.


Thin(?)/fat arrow (what do you call ->, thin arrow?) and object/array destructuring is amazing.


I'm constantly impressed by the quality of articles on 2ality. They're always both informative and succinct.


Why so much let? Are you supposed to only use let now? I thought it had a very specific use (like wanting a local variable in a loop).


> Are you supposed to only use let now?

Yes, if you can use `let`, there is no reason whatsoever to use `var` ever again.

If you want the `var` behavior, just put your declaration at the very top of the innermost function. With most code conventions, that's where you'd put a `var` declaration anyways.

For what it's worth, Crockford also recommended to use `let` exclusively as soon as you can.


I think let is supposed to replace var completely. There's a brief mention of this in a book I was reading the other day (Understanding ES6: https://leanpub.com/understandinges6/read/ ) but no citation of where that decision comes from.


you want everything to be local. local should be the default. Thou shalt not be implicitly global.


What's the timeline on everyone using ES6 in production and JavaScript developers being expected to know ES6? 2 years?


I'm using a lot of them in production right now, thanks to transpilers. Unfortunately not everything can work without the aid of a run-time, which is how Traceur works. At the moment i'm limiting myself to the features that don't require such a run-time.


Off the top of my head, features that are entirely syntactical transformations and don't need a runtime:

- Classes (except inheritance requires a tiny shim function)

- Destructuring (except destructuring iterators)

- Rest parameters

- Arrow functions

- Shorthand object literals

- Computed properties

- Template strings (although tagged template strings require a non-trivial amount of shimming to mimic)

- let and const (check correctness before transpiling, then compile to var. Transformation is non-trivial when inside loops, etc.)

- Modules

Features that do require a runtime / library:

- Iterators and generators

- Promises

- Symbols

- New ES6 methods on Object, Number, String, etc. (like Number.isNaN)


I think to use the more advanced features of modules, ie default exports, you do need a run-time.


Then why not use something like https://6to5.org/ ? Most syntax features can be transpiled without a runtime (generators being an exception) and everything else can simply use polyfills.


18 months - 2 years would be an appropriate time to use ES6 features safely without a transpiler (however we will still be using transpilers in the future for ES7 and ES8). But you can use them today using a transpiler like 6to5 or Traceur.


More makeup on a Gorilla doesn't turn it into a Lady.



Just include everything possible in the language. What could go wrong?

Although we already have C++.


Being able to (eventually) use all these language features in a language that's running inside a browser is blowing my mind right now. It's got iterators! It's got properties!


I find funny what you find "mind blowing".


State of ECMAScript-6 support in current browsers:

http://kangax.github.io/compat-table/es6/


It looks like a 2nd system effect to me or a cancer of the features.

In JS there are a lot of other stuff to fix before adding syntax. (non commutativity of ==).

But adding stuff like macro, confusing multiline chars it looks like a hell to maintain to me.

Hours of painfully finding what could have triggered the bug!

The code? The macro? Is this a ' or a ` ? ....

Hell, this is hell coming on us my fellow grunt programmers.


I'm not sure why you would add OOP features to a prototype based language.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: