Home > Software design >  Possible to use Sub-Functions in Apps Scripts (Google)
Possible to use Sub-Functions in Apps Scripts (Google)

Time:09-20

Is it possible to use Sub-Functions in Apps Scripts from Google ? Like call a function with Monday.Lock or something similar ?

function MONDAY () {
function .LOCK() {
    xxxxxxxxxx
  }
}
function .UNLOCK() {
    xxxxxxxxxx
  }
}
function .DELETE() {
    xxxxxxxxxx
  }
}

CodePudding user response:

Here is an example of how to create an object with the methods you mention.

class MONDAY {
  constructor(name) {
    this.name = name;
  }
  LOCK() {
    this.name = "LOCK";
  }
  UNLOCK() {
    this.name = "UNLOCK";
  }
  DELETE() {
    this.name = "DELETE";
  }
}

function testMONDAY() {
  let day = new MONDAY("hello");
  console.log(day.name);
  day.LOCK();
  console.log(day.name);
  day.UNLOCK();
  console.log(day.name);
  day.DELETE();
  console.log(day.name);
}

10:06:02 AM Notice  Execution started
10:06:03 AM Info    hello
10:06:03 AM Info    LOCK
10:06:03 AM Info    UNLOCK
10:06:03 AM Info    DELETE
10:06:03 AM Notice  Execution completed

Reference

CodePudding user response:

Google Apps Script is modern JavaScript with full support to classes that let you do what you are asking. See Clean Code JavaScript and MDN.

  • Related