10

Is there a way in ES6 to destructure a parameter and reference it by name as well?

myfunction(myparam) {
    const {myprop} = myparam;
    ...
}

Can this be done in a single line in the function parameter list? Something similar to Haskell's @ in pattern matching.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
akonsu
  • 28,824
  • 33
  • 119
  • 194

1 Answers1

3

There is no syntax support for this. I guess you could hack around this with something like:

const myFunction = (function() {
  function myFunction(myparam, {myprop}) {
    // ...
  }

  return function(myparam) {
    return myFunction(myparam, myparam);
  };
}());

or even

function myFunction(myparam, {myprop}=myparam) {
  // ...
}

but both may be considered too hacky.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143