Define an object parameter, but also have a parameter reference as an object?

With ES6, you can destroy objects in function arguments:

({name, value}) => { console.log(name, value) }

Equivalent to ES5 would be:

function(params) { console.log(params.name, params.value) }

But what if I need a reference to both the object paramsand the attached properties valueand name? This is the closest I got, but the disadvantage is that it will not work with arrow functions, because they do not have access to the object arguments:

function({name, value}) {
  const params = arguments[0]
  console.log(params, name, value)
}
+4
source share
2 answers

arguments not available in arrow functions, and this affects how function parameters should be processed sequentially in ES6.

If the original parameter is used, it must be destroyed inside the function:

(param) => {
  const {name, value} = param;
  // ...
}

(, arguments.length), rest:

(...args) => {
  const [param] = args;
  // ...
}

; param args , .

+1

:

function({name, value}, params=arguments[0]) {
    console.log(params, name, value)
}

:

function(params, {name, value} = params) {
    console.log(params, name, value)
}
0

Source: https://habr.com/ru/post/1694367/