This course has been updated! We now recommend you take the ES6: The Right Parts course.

Check out a free preview of the full JS.Next: ES6 / ES2015 course:
The "Questions" Lesson is part of the full, JS.Next: ES6 / ES2015 course featured in this preview video. Here's what you'd learn in this lesson:

Aaron answers a few audience questions on the benefits of destructuring. He also talks a little about compatibility and gives a couple last code examples before moving on.

Get Unlimited Access Now

Transcript from the "Questions" Lesson

[00:00:00]
>> [MUSIC]

[00:00:04]
>> Aaron Frost: Last call for questions on destructuring. Still got time, so we're gonna try this out for a few minutes.
>> Speaker 2: What are the best benefits of an array destructure?
>> Aaron Frost: Man, that's a good question, okay. So I've been meaning to talk about the specific benefits that we get out of each feature and I've been forgetting.

[00:00:23] So I was like, I told them to softball me the question if I forget. So destructuring doesn't have performance improvements, right? Nothing that I just showed you is something you can't already do. Do you guys agree? We've always been able to do what I just showed you. This is the sugar on top of the syntax though.

[00:00:47] It just makes it sweeter to see and easier to code and maintain and to just visualize. That make sense? So some of the things we've talked about do have some performance impacts and this may have some micro benefits, or whatever the opposite of a benefit is. But I think that they're probably negligible.

[00:01:09] So, yeah. Do I like Diet Coke? Dude, actually I hate Diet Coke, I really do. But it's the only diet drink he had. And so, good question, though. Anyone else, any questions?
>> Speaker 3: You said that the question mark thing isn't implemented yet. Is there any-
>> Aaron Frost: Is there any way you guys can try this out, is what you want to know.

[00:01:35]
>> Speaker 3: Now, also, is there a timeline when?
>> Aaron Frost: No.
>> Speaker 3: Is there-
>> Aaron Frost: Geez.
>> Speaker 3: Next version of Chrome, ten versions of Chrome from-
>> Aaron Frost: I have no idea, man. Yeah, I didn't prepare this presentation that well. [LAUGH] I would've had to get into Google's V8 bug log and see where it's at and then everything and I just didn't do that.

[00:02:04] It's slowly trickling out. When you get on to the compatibility list, I mean, like I said earlier, some of them say green but it's really kind of only partial. Like I told you earlier, Firefox claims let's on this list but it doesn't respect temporal dead zone. And it still has statements and expressions, which aren't a thing.

[00:02:27] So it's like, is that a real implementation? Should it be green? Should it be lighter green? Can I use it if it's kind of implemented? It's greenish. Maybe some of these should be greenish, and destructuring is definitely one of those. But if you guys wanna try it out real quick.

[00:02:47] So if we say var (name, age, address) = person.
>> Aaron Frost: It didn't fail, okay? So, okay, so I wrote the chapter on destructuring, that was one of the first ones I wrote and when I say first, I mean it was like two years ago, okay? And the idea of patterns, I didn't even have the word pattern in the chapter.

[00:03:26] It wasn't a thing that I needed to teach people. And it kind of came up later. And then the idea of irrefutable patterns versus refutable patterns was something that came out later and I was like, okay, so throw chapter away, rewrite chapter. I had to kinda start over.

[00:03:43] And so, these things are changing, and this is obviously an implementation. Firefox, or Mozilla, I should say, probably built this when, remember I told you we talked about the ES4 ES3 stalemate? So, Firefox, they didn't stop, neither did Adobe. They didn't just like well, we're gonna sandbag our language.

[00:04:07] They're over there implementing stuff, right? You guys can go to Mozilla's Bugzilla instance and you can see code commits on destructuring and generators, clear back in 2006 and 07. So they were working on this stuff during those stalemates. They were still forging ahead and adding new features. And it actually helped in the long run, because now that they're having conversations about well, how should destructuring work, they have some really valuable input, because they've already implemented it.

[00:04:36] And so like the destructure that you're gonna see in Firefox, or like this one that we see in Traceur, they're not solid. And they're working on them, but it's tough. It sucks, cuz some of the stuff you can kind of play around with. But we're still kind of cutting edge on a lot of this where we're not gonna be able to mess around with a lot of it, so.

[00:05:03] But, again, destructuring is mostly just the sugar on top of things you could already do in the language. So good question. Great, great, great, great question man. So, okay, all right, do you guys wanna to try it out for a few minutes? Maybe try some destructuring in a method signature.

[00:05:31] Go ahead and call a method in destructure, its return value. See if anyone wants to try and destructure like a canvas bitarray, sounds fun, right? I'll try and do that while we're working. But also, if you wanna read about them, and the refutable matching, here's two links that you can go to as well.

[00:05:52] If you just go to the Harmony proposals page, there's one called destructuring and one called refutable matching. And if you just go check those out, that is what you will use.