如何使用新功能扩展UiApp?

问题描述:

我想用包装功能在Google Apps脚本中扩展(原型)UiApp,但在运行如下所示的简单示例时出现TypeError ...
我做错了什么?

I would like to extend (prototype) UiApp in Google Apps Script with a wrapping function, but I am getting TypeError when running a simple sample like below... what am I doing wrong?

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);
}

谢谢

thanks

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

It is impossible to extend UiApp, Document, Spreadsheet and other high order classes. Google prevented it. If to execute the var isObject = UiApp.createApplication() instanceof Object; line then the isObject is false, although the typeof UiApp.createApplication(); expression returns object.