根据旧谷歌集团的这个帖子,Apps脚本基于ECMA-262第3版.
这似乎得到了编辑器中的自动完成显示第3版阵列功能这一事实的支持.
但是,以下代码运行得非常好,这使人对此事表示怀疑:
var array = [
1,2,3,4,5
];
Logger.log("forEach:");
array.forEach(function (item,idx,arr) {
Logger.log(item);
});
Run Code Online (Sandbox Code Playgroud)
请注意每个使用ECMA-262第5版阵列功能.
有权威的人会给出明确的答案吗?为什么会这样?是否可以安全地依赖所有第5版功能或已经实施并且似乎有效的子集?
鉴于此Google Apps脚本脚本:
'use strict'
const foo = 2;
function bar() {
Logger.log(foo + 2);
}
Run Code Online (Sandbox Code Playgroud)
运行该函数会bar导致aTypeError: redeclaration of const foo.
为什么?怎么foo被重新宣布?
我正在尝试在Google电子表格中使用ES6(在script.google.com部分中).我是JavaScript的新手,也许这个错误很简单......
SomeClass.我正在寻找模块,因为我的声明不是好的我做了什么:
ReferenceError:SomeClass这是我的代码:
SomeClass.js
export default class SomeClass {
constructor() {
this.loggerSheet = SpreadsheetApp.getActiveSpreadsheet()
.getSheetByName("ImportLog");
}
LogInfo(data) {
Logger.log(data);
loggerSheet.appendRow([new Date(), "INFO", data]);
}
}
Run Code Online (Sandbox Code Playgroud)
Main.js
import SomeClass from './SomeClass.js';
Run Code Online (Sandbox Code Playgroud)
在script.google中测试
function test_bundle() {
var someClass = new SomeClass(); //<== breaks here
}
Run Code Online (Sandbox Code Playgroud)
Bundle.js =>复制/粘贴到script.google
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) …Run Code Online (Sandbox Code Playgroud) javascript google-sheets google-apps-script ecmascript-6 webpack
Google Apps脚本似乎无法识别该功能Object.assign()。尝试使用它时出现错误:
TypeError: Cannot find function assign in object function Object() { [native code for Object.Object, arity=1] }
Run Code Online (Sandbox Code Playgroud)
我测试功能的代码是直接从MDN复制的示例:
function myFunction() {
const object1 = {
a: 1,
b: 2,
c: 3
};
const object2 = Object.assign({c: 4, d: 5}, object1); //error is thrown here
console.log(object2.c, object2.d);
// expected output: 3 5
}
Run Code Online (Sandbox Code Playgroud)
我将上面的代码直接复制粘贴到Chrome开发者控制台中,该控制台运行良好并提供了预期的输出。
我在网上找不到任何内容说应用程序脚本不支持此特定功能或类似功能。发生什么了?我怎样才能解决这个问题?