With ES6 you can destructure objects in function arguments:
({name, value}) => { console.log(name, value) }
The equivalent ES5 would be:
function(params) { console.log(params.name, params.value) }
But what if I would like a reference both to the params
object and the nested properties value
and name
? This is the closest I got, but the drawback is that it won't work with arrow functions because they do not have access to the arguments
object:
function({name, value}) {
const params = arguments[0]
console.log(params, name, value)
}
function(params){const {name,value}=params;console.log(params,name,value)}
? – Lekishalelafunction({name,value}=params)
– Wingfooted