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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With