5 ms·
ECMAScript 6: new OOP features besides classes
- recursive 12y agoBeing 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 12y agoI find funny what you find "mind blowing".
- gargarplex 12y agoWhat's the timeline on everyone using ES6 in production and JavaScript developers being expected to know ES6? 2 years?
- andrewingram 12y agoI'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 12y agoOff 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 12y agoI think to use the more advanced features of modules, ie default exports, you do need a run-time.
- thejameskyle 12y agoThen why not use something like https://6to5.org/ https://6to5.org/ ? Most syntax features can be transpiled without a runtime (generators being an exception) and everything else can simply use polyfills.
- zghst 12y ago18 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.
- igl 12y agoFirst 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.
- zghst 12y agoWe don't have to wait to use these features, we can use them today with Traceur, 6to5, ES6ify, etc.
- rauschma 12y agoYou 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 12y agoI am mostly looking forward to Proxies and Tail calls, both cannot be implemented with traceur :/
- mixonic 12y agoHaving 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.
- dpweb 12y agoI'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 12y ago>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.
- andrewstuart2 12y agoJavascript books get bigger, "The Good Parts" stays the same.
- tracker1 12y agoI'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.
- kelvin0 12y agoMore makeup on a Gorilla doesn't turn it into a Lady.
- Hypx 12y agoState of ECMAScript-6 support in current browsers: http://kangax.github.io/compat-table/es6/ http://kangax.github.io/compat-table/es6/
- bsimpson 12y agoI'm constantly impressed by the quality of articles on 2ality. They're always both informative and succinct.
- bradchoate 12y agoI guess the guy that proposed an '====' operator lost to the guy that proposed a 'Object.is()' method.
- Kiro 12y agoWhy 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).
- whostolemyhat 12y agoI 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/ https://leanpub.com/understandinges6/read/ ) but no citation of where that decision comes from.
- _ZeD_ 12y agoyou want everything to be local. local should be the default. Thou shalt not be implicitly global.
- ahoge 12y ago> 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.
- LunaSea 12y agoI'm not sure why you would add OOP features to a prototype based language.
- julie1 12y agoIt 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.