Google 个 Apps 脚本的 V8 运行时

V8 Runtime for Google Apps Scripts

上周 Google 发布了一个新的 Runtime。 谁知道用的是哪个版本的V8或者ECMAScript?

根据 migrating scripts to v8 docs V8 standards_compliant.

然而,当将您的脚本迁移到 V8 时,可以 some incompatibilities that you need to address or your scripts can break. While Mozilla's Rhino JS Interpreter 为 Apps 脚本提供一种方便的方式来执行开发人员脚本,它还将 Apps 脚本绑定到特定的 JavaScript 版本 (ES5)

V8 实现 ECMAScript 2020.

这里有some V8 syntax examples

希望对您有所帮助。

嗯,我可以说我们有最新版本的 ECMA262:

这里以第10版的一些例子,介绍几个新的内置函数:flat和flatMap:

function TEST_Flats() {    
    const arr = ['a', 'b', ['c', 'd']];
    const flattened = arr.flat();
    console.log(flattened);  
}

从另一个版本我们有:

function TEST_REST_SPREAD() {
  // ECMAScript® 2018 Language Specification (ECMA-262, 9th edition, June 2018)
  const arr1 = [10, 20, 30];
  const arr2 = [40, 50];

  // make a copy of arr1
  const copy = [...arr1];  
  console.log(copy);    

  // merge arr2 with arr1
  const merge = [...arr1, ...arr2];
  console.log(merge);       
}

function TEST_PAD() {
  // ECMAScript® 2017 Language Specification (ECMA-262, 8th edition, June 2017)
  let data = { "King" : "Jon Snow",
             "Queen" : "Daenerys Targaryen",
             "Hand" : "Tyrion Lannister"}

  console.log(Object.entries(data));  
  console.log(Object.values(data));  

  console.log('a'.padStart(5, 'xy'))  
  console.log('a'.padStart(4, 'xy')) 
  console.log('1234'.padStart(2, '#')) 
  console.log('###'.padStart(10, '0123456789')) 
  console.log('a'.padStart(10)) 

  console.log('a'.padEnd(5, 'xy'))  
  console.log('a'.padEnd(4, 'xy')) 
  console.log('1234'.padEnd(2, '#')) 
  console.log('###'.padEnd(10, '0123456789')) 
  console.log('a'.padEnd(10))

}

function TEST_PropertyDescriptors() {
  // ECMAScript® 2017 Language Specification (ECMA-262, 8th edition, June 2017)
  const obj = {
    id: 123,
    get bar() { return 'abc' },
  };
  console.log(Object.getOwnPropertyDescriptors(obj));
}