• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

You don't know JS: what features of EcmaScript 6 make Javascript a joy to learn and use?

 
Ranch Hand
Posts: 343
Mac OS X Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kyle,

As per you which of the features introduced in ES 6 make JavaScript more fun to learn and code?

 
whippersnapper
Posts: 1843
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Little syntactic-sugar functions like the following bring me more joy than they probably should.

Array.prototype.includes
String.prototype.includes
String.prototype.startsWith
String.prototype.endsWith

Oh, and Array.prototype.find.
 
Author
Posts: 22
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My favorite features of ES6 are:

* destructuring (https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch2.md#destructuring)
* `...` spread/gather/rest operator (https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch2.md#spreadrest)
* interpolated string literals, aka "template literals" (https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch2.md#template-literals)
* generators + promises, for sync-looking async (https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch3.md#generators and https://github.com/getify/You-Dont-Know-JS/blob/master/es6%20&%20beyond/ch4.md#generators--promises)

The proper way to think of ES6 features is that they're not new things you couldn't do before, but better (more readable, understandable) ways of doing old things. The more understandable your code is, the longer life it will have as new developers come to your code (or you, later) and can understand it and fix it instead of not understanding and just replacing.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kyle Simpson wrote:generators + promises, for sync-looking async


There seems to be a point of view that promises are merely a special case of observables (aka event streams) - apparently to the extreme that at Netflix there was a directive to stop using promises and use RxJS observables instead (Promise to not use Promises – ES7 Observables by Brian Holt).
 
Kyle Simpson
Author
Posts: 22
5
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there are those who have made that claim. I respectfully think it's because they're missing the most important part of a promise -- that it's a time-independent immutable value wrapper. Observables are great, but they're not the hammer I hit every nail with.

I just wrote a blog post that sorta comes at this from that different perspective: Thoughts On Thunks (http://blog.getify.com/thoughts-on-thunks/)
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great article and I see your point. While reading it I started to wonder whether there was another motivation behind the "Netflix directive" - the fact that our thinking is often shaped by tools that we use.
Looking at the promise based "eager async thunks" there seems to be a lot of "ceremonial code" for dealing with what essentially seems to be a one-off result. Given your example, in the most general case you may actually want to eagerly fire off all the questions and process the answers as soon as they become available and in any order - at which point employing an observable may make sense (especially if the answers are processed uniformly). So while promises certainly have their place, observables could enable different types of solutions which depending on the circumstances could be "easier to reason about".
 
Kyle Simpson
Author
Posts: 22
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Observables are about getting and processing a "stream" of multiple values for a single subscription/request. This is different from having multiple promises, which are more conceptually multiple *independent* request/response type transactions. Broadly speaking, the observables hype seems to suggest that you can just have a single message observable and it serves the same purpose as a promise. That's not really true in all senses, but it's close enough to sound convincing as a hype statement.

But a single message observable is a much bigger hammer for the purpose of a single transaction's value. A promise is more direct for that specific purpose. It's kinda like comparing using a sledgehammer and a ball-pin hammer. They both are roughly used to drive thin pieces of metal into wood... but a sledgehammer is better for big spike nails and a ball-pin hammer is better for tiny picture hanging nails. Can you do each of those jobs with the other respective tools? Sure. But it's not a good idea.
 
snakes are really good at eating slugs. And you wouldn't think it, but so are tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic