If I have an object like this
const obj = {
func: props.func, // we don't know if func is a function or undefined...
}
and I have this in my code:
obj.func(params);
What is the good way to execute the optional function of the object?
I have thought to do something like this:
if(typeof obj.func === "function")
obj.func(params);
or
try {
obj.func(params);
} catch (err) {}
But I'm not sure if both forms are correct to do it (or if there is a better way) as I don't have much experience with javascript.
Someone who knows? Thank you.