Skip to content

Would recommend destructuring in function args 2 or less #159

@bali182

Description

@bali182

This is absolutely not helpful, when you are trying to find out what kind of keys do the config object accept.

function createMenu(config) {
  // ...
}

createMenu({
  title: 'Foo',
  body: 'Bar',
  buttonText: 'Baz',
  cancellable: true
});

This however makes it perfectly clean exactly which keys are used:

function createMenu({ title, body, buttonText, cancellable }) {
  // ...
}

There are no sneaky magic properties accessed in the call chain later, since you don't have the reference to the original config object. I would highly recommend suggesting this version. Also while coding, if you have a linter, it will tell you if you have an unused prop in the destrucutured object while it will have no chance of warning you if you just take it as a regular argument.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions