如何使用新功能扩展UiApp?

时间:2012-08-29 19:58:17

标签: google-apps-script

我想使用包装函数在Google Apps脚本中扩展(原型)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);
}

感谢

1 个答案:

答案 0 :(得分:3)

无法扩展UiApp,Document,Spreadsheet和其他高阶类。谷歌阻止了它。如果要执行var isObject = UiApp.createApplication() instanceof Object;行,则isObject为false,尽管typeof UiApp.createApplication();表达式返回object