如何使用新功能扩展UiApp? [英] How can I extend UiApp with a new function?

查看:86
本文介绍了如何使用新功能扩展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.

这篇关于如何使用新功能扩展UiApp?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆