Skip to content Skip to sidebar Skip to footer

How To Call This Default Args Function More Than Once?

I have encountered a question where I need to allow default args to be set on a function in JavaScript: However, I need to be able to call this function more than once and overwri

Solution 1:

Instead of your complicated default args thing, why not just use some arrow functions with real default arguments:

var _add = (a, b = 8) => add(a, b);

That way you can easily change the bound things:

varadd_ = (a = 2, b) => _add(a, b);
 add_() // 10

Post a Comment for "How To Call This Default Args Function More Than Once?"