google-apps-script - 如何使用新功能扩展 UiApp?

标签 google-apps-script

我想使用包装函数在 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/

相关文章:

javascript - 使用谷歌脚本自动将 CSV 输出到谷歌表格

google-apps-script - 如何在谷歌电子表格中每行添加一个按钮?

javascript - 对 localhost 的 CORS https 访问在 Chrome 上有效,但在 Firefox 上无效

javascript - 同步独立的电子表格行,由 IMPORTRANGE() 填充

google-apps-script - Google 表单确认脚本

javascript - 在 Google Apps 脚本中,无法以编程方式创建触发器以从 onEdit 触发器发送电子邮件

javascript - 如何使用不同的值多次加载相同的 html

javascript - Google 协作平台 HTML Iframe(不是小工具)

javascript - 如何使用Google Apps脚本将视频上传到YouTube?

javascript - 如何自动随机化 46 个名称以在 Google 表格中创建 46 x 6 唯一行和列?