How do I clean up my global space without having to create +1000 lines .gs
files
.gs
files cannot be manually mixed like .js
modules, which means I cannot import
or export
(right?), neither control what will be shown when you search for completions;function groupOfFunctions() {
this.doThis = function() { /* hundreds of lines */ };
this.doThat = function() { /* hundreds of lines */ };
// ...
this.subFunc_N = function() { /* hundreds of lines */ };
return this; // <-- makes tired face after this
};
How do I clean up my global space without having to create +1000 lines .gs
files
Articles, blogs, videos etc. are welcome.
Years later, after reviewing my own question, I conclude that:
globalThis
looks excessive, at first; however, usage has tought me that each item listed after pressing ctrl
+space
was carefully made easy, by design, because you'll often use them.I used to write code like seen below:
function getSpreadSheet() {//code...};
function getStudentsSheet(){//code...};
funcrion getStudentsDataRange(){
return getStudentsSheet().getDataRange()}
function getStudentsSheetValues(){
return getStudentsSheetDataRange().getValues()};
function logValues() {
console.log( getStudentsSheetValues() );
};
While it could be simply:
function logValues() {
const id = '...'
const values = SpreadsheetApp
.openById(id)
.getSheetByName('Students')
.getDataRange().getValues();
console.log(values);
}