28

var { name: x } = person
Day 1 : that's some good ES6 code man, I'm so 2017
Day 5 : Oh yeah I think it works, dont really remember
Day 17 : WTF is that ? Is that even Javascript ?

Comments
  • 0
    Just in case look at destructuring assignement
  • 1
    @AdrienITTS learn about it yesterday! Great little feature!
  • 1
    What's that? Someone can explain?
  • 1
    @pagrette that's equal to var x = person.name
    You can do something like :
    var { name: x, surname: y, age: z } = person
  • 7
    Ok I see thanks.. but I don't like, it's very not a clear way so source code is not easy to read
  • 3
    @pagrette terrible readability, but better than repeating the code over and over; x = person.name, y = person.age, etc.
  • 1
    It's really not very 2017 if you're still using var... Better to use let or const as appropriate.

    Otherwise yeah, little weird looking, but if it's unclear, comment it!
  • 0
    @nmunro yeah true, but wanted to show only one "New thing"
  • 1
    The thing where ES6 starts to confuse is nested higher order arrow functions.

    Stuff life this is still useful and readable:

    const invert = f => (...a) => !f(...a);

    const is = prop => value => obj => obj.hasOwnProperty(prop) && obj[prop] == value;

    isCat = is('type')('cat')

    So you can do things like animals.filter(invert(isCat))

    But eventually people are going to use combinators in js...
    f=>((x)=>f((v)=>x(x)(v)))((x)=>f((v)=>x(x)(v)))
  • 0
    Happened every time, last year. Now I never use dat again. Moved to python and their silly indent
Add Comment