Home > Software engineering >  How to declare Class fields in Google App Script using javascript
How to declare Class fields in Google App Script using javascript

Time:02-11

I'm trying to create a class with some fields on Google Scripts. I can't even save the file. From what I understand of this SO answer, I'm using the correct syntac for class fields.

V8 runtime is enabled.

The error:

Syntax error: ParseError: Unexpected token = line: 5 file: Airtable_Class.gs

Line 5 is: foo = "bar";

Here's the whole code:

class FieldsTest{
  foo = "bar";
}

CodePudding user response:

This is a known issue. Add a star (★ on top left) to the issue, if you want this to be implemented.

https://issuetracker.google.com/issues/195752915

According to the tracker, it is supported, but it is blocked by the parser.

CodePudding user response:

I was trying around and was able to define the class setting it up like this:

class Test{
  constructor(foo){
    foo = "bar";
  }
}

I was checking the documentation and it suggest to build up classes like the ones shown in the reference.

  • Related