Post

Ok... plenty of languages does this? :^) But do they also support labeled arguments!?

p1xelHer0@p1xelher0.com

Haven't really thought too hard about this but is there a language out there that supports default parameters, but the default value is based on some of the other parameters to the function?

0 reposts1 like

if you extend your definition of labeled arguments to include destructured objects js still is a contender 😅 example = ({ w, h = w * 2 }) => console.log(`width: ${w}, height: ${h}`)

I had to check, does it toposort? But no, it's ordered: > example = ({ w = h * 2, h = w * 2 }) => ({w,h}) > example({w:10}) { w: 10, h: 20 } > example({h:10}) ReferenceError: Cannot access 'h' before initialization > example({}) ReferenceError: Cannot access 'h' before initialization