Pass objects instead of values on functions
Passing objects in the functions would allow us to define defaults in the functions and only write the desired parameters to change. This is usually recommended because it improves scalability
An example I recently stumbled with (see attached image for visual example):
Old
function(title, class_, size='sm', keyboard=true)
New (bad)
function(title, class_, size='sm', keyboard=true, small=undefined)
New (desired)
function(title, class_, { size: 'sm', keyboard: true, small: undefined })
Usage (old)
function('My title', 'lg', 'sm', true, 'My small title')
Usage (new)
function('My title', 'lg', { small: 'My small title' })
Files
Download | Creator | Timestamp | Type |
---|---|---|---|
function-object-usage.png | @hodeinavarro | 2022-08-13 12:06:41.832000 UTC | image/png |