Skip to content
Advertisement

ES6 Partial Object Destructuring Default Parameters In A Separated Object

Okay so there’s a lot of similar questions here but none that actually address this. What if I want to save the default parameters of a function on a separated object, in a separated file and then I want the function to use this default parameters only if not specified when calling it?

Example:

JavaScript

And then in another file:

JavaScript

What I want for it to do is that calling

JavaScript

should print

JavaScript

But that’s not how that works and I’m trying to figure this out. Anyone knows how to achieve this?

Advertisement

Answer

You won’t be able to do it directly in the parameter, but you can inside the function..

eg..

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement