Default Parameters on Functions
I can't find any reference to this feature on the guides or scripting API and I wonder why it is not implemented.
it would be really helpful to be able to do something like
myfunction() and myfunction( value1 )
function myfunction( parameter1 = "defaultvalue" ){
dosomethingwithparameter1(parameter1);
}
where the option to not give a parameter is backed up by the default value.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters
Keep up the good work!
best regards.
Hi Aitor,
Lens Studio supports an older version of javascript from before that feature was added, so unfortunately it's not currently available. We may support it in the future though!
In the meantime, you can follow a workaround on the page you linked to:
Basically, if a parameter isn't given it defaults to undefined. So you can check if a parameter is undefined and use your default value instead. This is less convenient than the built-in version but hopefully should still help!
Let me know if you have any more questions!
Jacob
Oh, I see.
I have been using the workaround so far but it'd be nice to have the feature in the future.
Thank you for your response!
Best regards.