ryanmcdermott / clean-code-javascript

:bathtub: Clean Code concepts adapted for JavaScript
MIT License
91.21k stars 12.23k forks source link

Query regarding code #451

Closed hrohilla2k4 closed 6 months ago

hrohilla2k4 commented 6 months ago

Author asked to have only two or fewer parameters ideally. Bad function createMenu(title, body, buttonText, cancellable) { // ... }

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

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

What is the difference? Can anyone help me!.

iirving commented 6 months ago

Yes, It is confusing and not clear.

I (think) the point is that the { title, body, buttonText, cancellable } object are all related to each other and are the basic non optional items. It would be strange to have a body text without a title text.

Those item might be coming for a common place, and generally based around together. You could destructure them and pass then in separately but then it would be easier to make a mistake. So having a item object is useful. And passing them in as one make sense.

hope this helps

hrohilla2k4 commented 6 months ago

Yes - I got it, thankyou @iirving.