我想使用包装函数在 Google Apps 脚本中扩展(原型(prototype))UiApp,但是在运行如下所示的简单示例时出现 TypeError ... 我做错了什么?
Object.prototype.addLabel = function(text) {
this.createLabel(text);
return this;
}
function testingxUiApp() {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setTitle('playing around UiApp').setHeight("250");
var panel = app.createFlowPanel().setId('panel');
app.add(panel);
panel.add(app.addLabel("adding label for testing"));
doc.show(app);
}
谢谢
最佳答案
无法扩展UiApp、Document、Spreadsheet等高阶类。谷歌阻止了它。如果要执行 var isObject = UiApp.createApplication() instanceof Object;
行,则 isObject
为 false,尽管 typeof UiApp.createApplication();
表达式返回 object
。
关于google-apps-script - 如何使用新功能扩展 UiApp?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12185587/