1

I'm trying to understand this alexa skill but I've never seen this:

const {
      playbackInfo,
      playbackSetting,
    } = await handlerInput.attributesManager.getPersistentAttributes();

You can find on line 48 here. Also at line 42 is not clear. What's the meaning when I see something like const {a,b} = await foo(); or const {a,b} = foo; I always seen const = something. I couldn't find it in the new ES6 features.

Mattia
  • 130
  • 10
  • 3
    Possible duplicate of [Javascript object bracket notation ({ Navigation } =) on left side of assign](https://stackoverflow.com/questions/26999820/javascript-object-bracket-notation-navigation-on-left-side-of-assign) as listed on [this reference question](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript). – IMSoP Dec 14 '18 at 15:01
  • https://medium.com/dailyjs/asynchronous-adventures-in-javascript-async-await-bd2e62f37ffd – Josh Adams Dec 14 '18 at 15:02

1 Answers1

4

1) handlerInput.attributesManager.getPersistentAttributes() returns a promise.

2) await waits for the promise to be resolved

3) const { a, b } deconstructs the object that is returned when the promise is resolved.

Andy
  • 39,764
  • 8
  • 53
  • 80
  • That's what I was looking for, the destructuring assignment. I don't know why I didn't find it before asking. My bad. – Mattia Dec 14 '18 at 15:15