Destructuring is a new feature of JS that allows you to break apart stuff into variables.

1.pmg.PNG

In one line, you can take any JS object and break it into it’s constituted variables. These are sometimes referred to as JS options objects.  And they can be used for optional parameters. Like in this jQuery.ajax function.

$.ajax({
    url: "http://date.jsontest.com/",
    success: function (data) {console.log(data);},
    cache: true,
    timeout: 500
});

Here is an example of how to call a method with option objects.

2.png

No if you wanted to make a property, like species, optional, one way would be to do it like this.

3.png

But a better way, would be to set the options right int the constructor of the method itself.

4.png

Pretty slick. Thanks mpj for the great video explaining how all this works.

 

Advertisements