
ECMAScript 6: new OOP features besides classes - StylifyYourBlog
http://www.2ality.com/2014/12/es6-oop.html
======
igl
First we have to wait for complete implementations.

Then wait for v8 performance: [http://jsperf.com/performance-frozen-
object](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.

~~~
rauschma
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](https://github.com/google/traceur-compiler)

* 6to5: [https://6to5.org/](https://6to5.org/)

* es6-transpiler.js: [https://github.com/termi/es6-transpiler](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](http://www.2ality.com/2014/08/es6-today.html)

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

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

------
dpweb
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.

~~~
Arnavion
>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.

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

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

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

------
Kiro
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).

~~~
ahoge
> _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.

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

~~~
andrewingram
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.

~~~
Arnavion
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)

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

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

~~~
jbeja
Ironically:
[http://ckknight.github.io/gorillascript/](http://ckknight.github.io/gorillascript/)

------
recursive
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!

~~~
jbeja
I find funny what you find "mind blowing".

------
Hypx
State of ECMAScript-6 support in current browsers:

[http://kangax.github.io/compat-table/es6/](http://kangax.github.io/compat-
table/es6/)

------
julie1
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.

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

