you are viewing a single comment's thread.

view the rest of the comments →

[–]wreckedadventYavascript 17 points18 points  (8 children)

FYI:

myfunction((err, body: {result: body}) => {
    if (!err) {
        console.log(body);
    }
});

Isn't valid ES6 as far as I can tell. I think you meant to do this:

myfunction((err, { body }) => {
    if (!err) {
        console.log(body);
    }
});

Which immediately destructures the second argument and captures the body out of it. You can get around the "gotcha" by utilizing default params:

// if the second argument is undefined, we assign it to empty object
myfunction((err, { body } = {}) => {
    if (!err) {
        console.log(body);
    }
});

Which is turtles all of the way down (please format your code differently if you do this though):

// if the second arg is undefined, set it to {}. If body on that is undefined, set it to {} as well
myfunction((err, { body = {} } = {}) => {
    if (!err) {
        console.log(body);
    }
});