I attempted to use Private class features in Google Apps Script, using the following snippet:
class Feed
{
#user;
#password;
url;
constructor(url, credentials)
{
// class constructor
this.url = url;
this.#user = credentials.user;
this.#password = credentials.password;
}
}
with the intention of calling it in the following manner:
const url = "https://URL"
const credentials = {user: 'user', password: 'password'};
let feed = new Feed(url, credentials);
On saving the file, the following error was displayed, appearing to indicate that private class features aren't supported in Google Apps Script:
Syntax error: ParseError: Unexpected token ILLEGAL line: 3 file: Testing.gs
I removed the '#' on line three, as shown below:
class Feed
{
user;
#password;
url;
constructor(url, credentials)
{
// class constructor
this.url = url;
this.#user = credentials.user;
this.#password = credentials.password;
}
}
and received the following error on saving:
Syntax error: SyntaxError: Private field '#user' must be declared in an enclosing class line: 11 file: Testing.gs
I searched, and found Define private class fields with Google Apps Scripts (GAS) V8 which indicated that (at the time) private class features weren't supported in Google Apps Script. While the first error message seems to confirm that this is the case, the second implies that Apps Script understands private class fields.
Questions:
- Are private class fields supported by Google Apps Script (v8)?
- If so, how are they supposed to be implemented?
Thanks,
Fergal
WeakMap
s for the time being.