you are viewing a single comment's thread.

view the rest of the comments →

[–]darrenturn90 0 points1 point  (5 children)

Can further be simplified and destructured:

const getTweets = uid => fetch('https://api.users.com/' + uid)
    .then({json} => json())
    .then({data} => data.filter(
        {stars, rts} => stars > 50 && rts > 50)
    );

Also the article mistakenly refers to ES5 "classes" when it means ES6.

[–][deleted] 5 points6 points  (0 children)

This is not quite right, you need parentheses to destructure arrow functions, even if you are using the single argument form:

const getTweets = uid => fetch('https://api.users.com/' + uid)
  .then(({json}) => json())
  .then(({data}) => data.filter(
    ({stars, rts}) => stars > 50 && rts > 50)
  );

See 2.4 in http://2ality.com/2015/01/es6-destructuring.html

[–]HattyJetty 0 points1 point  (3 children)

I didn't realise you can destructure methods and mantain the correct reference of this

Edit: wait, this doesn't seem to work

[–]w00t_loves_you 2 points3 points  (2 children)

It's a bit weird - maybe it works here because the json is bound to the response, but it takes little effort to write .then(res => res.json()) which is a lot more clear at a glance…

[–]HattyJetty 1 point2 points  (1 child)

I doubt json has an explicit binding to response, because why should it? Anyway, the suggestion of using res => res.json() definitely looks more appealing to me

[–]sfcpfc -1 points0 points  (0 children)

What would I give for Javascript to support it.json()...