LoginSignup
2

More than 3 years have passed since last update.

Google Apps ScriptのランタイムにV8が採用された話

Posted at

GASでES2015が使えるようになったらしい

以下のページを見ると、ランタイムとしてV8が使えるようになったっぽいです。
Google公式発表

V8ランタイムが使えるようになったということは、ついにGASにES2015が来たということです。
早速使ってみましょう。

プロジェクトを作成して、マニフェストファイルに"runtimeVersion": "V8"を追加しましょう。

appsscript.json
{
  "timeZone": "Asia/Tokyo",
  "dependencies": {
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

とりあえず、class構文を使ってみましょう。

コード.gs
class Rectangle {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }

  get area() {
    return this.height * this.width;
  }
}

function myFunction() {
  const rec = new Rectangle(100, 200);
  Logger.log(rec.height);
  Logger.log(rec.width);
  Logger.log(rec.area);
}

image.png

おぉー、使えた。

まとめ

GASが便利になった

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2