dimanche 18 septembre 2016

ES6 - Default parameter combined with Destructuring : How is this pattern meant?

I've seen these pattern in a CodeReview question:

toggleModal({title = null, description = null, cancelLabel = 'No', submitLabel = 'Yes'} = {}) {
    this.setState({
        modalVisible: !this.state.modalVisible,
        title: title,
        description: description,
        cancelLabel: cancelLabel,
        submitLabel: submitLabel
    });
},

The complete post: http://ift.tt/2dczfHO

I would say it's a combination of ES6 Default Parameter with Destructuring.

Have tried to understand the purpose. But still not idea.

Why aren't Default Parameter used alone?

Can anyone explain me what this pattern is about?

Aucun commentaire:

Enregistrer un commentaire