Skip to content

Fancy Function Parameters of JS

chenge profile image chenge github logo ・1 min read  

The code is from this post. It makes the params more clear.

function renderList(list, { 
    ordered = true,
    color = '#1e2a2d',
    bgColor = 'transparent'
} = {}) {
    /* ... */

// simple use
renderList(['love', 'patience', 'pain'])

// with all arguments
renderList(['one', 'two'], { ordered: true, color: '#c0ffee', bgColor: '#5ad' })

// with only one optional argument (bgColor)
renderList(['one', 'two'], { bgColor: '#5ad' })
twitter logo DISCUSS
markdown guide
Classic DEV Post from Jul 30 '19

PublishTo.Dev: Scheduling article publishing on

chenge profile image
Ruby, and learn Rust, Go, Elixir, Erlang...