google-apps-scriptmodulecode-organizationproject-organizationglobal-scope

GAS files: how to free global space from polution?


How do I clean up my global space without having to create +1000 lines .gs files

Files and folders used in my project enter image description here

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
};

enter image description here enter image description here

How do I clean up my global space without having to create +1000 lines .gs files

Articles, blogs, videos etc. are welcome.


Solution

  • Years later, after reviewing my own question, I conclude that:

    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);
    }