0

how can I get original object before destucturing?

const a = {mi: 2, ti: 'TI'};

function destruct({mi: a}) {
  return a === 1 ? arguments[0]: 'Sorry';
}
console.log(destruct(a)) // return original obj or 'sorry'

How I can get the object itself? Before it was destructed? My only guess is arguments[0] as above? But may be there is a better way to destruct the object in argument parentethis, and get it afterwards?

Mihey Mik
  • 1,643
  • 13
  • 18
  • you meant `destruct(a)`, I suppose – RomanPerekhrest Feb 02 '17 at 07:18
  • corrected the example – Mihey Mik Feb 02 '17 at 07:22
  • Start here: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment . If you are destructuring then by rights it means you aren't interested in the original object, otherwise you should just return that and do your destructuring later. You are trying to create a paradox. That's like asking how to get the original branch from a woodchip. – SpliFF Feb 02 '17 at 07:23
  • I wouldn't agree, because when we destruct it in a function, like const {a} = obj, we don't erase the obj, we only get the properties we need... so I thought it was a way... – Mihey Mik Feb 04 '17 at 16:07

0 Answers0