I'm returning to gapps with sheets after a long break and an upgrade to the V8 engine.
When using function declarations I get the issue of the function being overwritten by a 2nd declaration such as below as an example (I know overloading is not supported) if the same function name is accidentally reused.
function stuff() {
return (`I'm doing stuff`);
}
function stuff() {
return (`I'm doing stuff and things`);
}
function __test_stuff() {
Logger.log(stuff());
}
// logging : "I'm doing stuff and things"
There can be a 2nd ( or n'th ) declaration which can be another .gs file in the project and the code will run without error, but not sure which code is running!
Should I be using const function expressions as
const stuff = function stuff(e) {
return ("I'm doing stuff, things and much much more");
}
These give an error when trying to run with multiple declarations SyntaxError: Identifier 'stuff' has already been declared (line 1, file "stuff")
Is this a good thing as it stops the function being overridden or are there gotcha's waiting in the wings?
nb. I have been splitting code into separate .gs files per function as my eyes were glazing over. Again is the a good thing?