Let’s try ECMAScript in New GAS version〜setting and use Arrow Function〜

GAS
この記事は約6分で読めます。

At last! I feel strong, but GAS now supports ECMAS. It doesn’t seem to be everything, but it seems like we can finally move from old Javascript to a bit more modern Javascript.

That’s why I want to play with it immediately.

Advertisements

Changes Points on GAS runtimeVersion V8 (ECMAScript support Version)

Many changes points are for GAS runtime Version V8.

Newly supported features as following list:

  • let
  • const
  • class
  • arrow function
  • template literals and Multi-line strings
  • default argument etc…

Let’s check original document as linked follow.

V8 Runtime Overview  |  Apps Script  |  Google Developers

How to convert to v8 version

as dscritbed in official document, in script editor menu Select the Run > Enable new Apps Script runtime powered by V8. and it make version change from Rhino(current version) to V8(ECMAScript support version)

on 2020/2/13, “Enable new App Script runtime powered by V8” button is activated!!

However, at this moment(I make this article on 02/07/2020), unfortunately not appeared this item…

Run tab

With that said, we’ll go over the other suggested method:

step1: [View] > [Show manifest File]
step2:  the resulting appsscript.json manifest file, set the runtimeVersion field to the value V8

Lets’ do it!

How to set manifest File

Well, it is a manifest file, but it only points to a json file for setting appscript.

How to open Manifest file and set V8

Step1: [View] > [Show manifest File] click

Step2: when opening json file, inserting “runtimeVersion”:”V8″ as following img

Step3: Save

Let’s try with the arrow function

It is a simple triangle area calculation as soon as we try the arrow function.

Using arrow function and “let”.

Run and checking Log….. ups, just a little be slowly logging…

ログ待機画面が出るようになった

After a short wait, I was able to execute safely.

Finally,

I’m very happy to support ECMAScript. You should be able to use let and const properly, and you will gradually reduce the trouble with the gap between JS that you use regularly (I do not know whether it is ES5 or ES6, so it is unclear whether it covers all)

Also, it seems that the logging display is a bit slow, so it might be a good idea to check the log on the App Script dashboard.

Additional on 2020/2/13

Finally, menu bar in script editor, Run > [Enable new Apps Script runtime powered by V8], is appeared!!

Before/After clicking button, i will explain simply how change appscript.json file.

V8 Disable -> Enable

when clicking Enable new Apps Script runtime powered by V8, as I mentioned in “How to set manifest File” in this post, ”runtimeVersion”:”V8″ is inserting to appscript.json file automatically.

V8 Enable -> Disable

The other, when clicking “Disable new Apps Script runtime powered by V8”, “runtimeVersion”: “V8” is changed ”runtimeVersion”:”DEPRECATED_ES5″ in appscript.json file automatically.

コメント