Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I extend UiApp with a new function?

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

like image 981
Fausto R. Avatar asked Jan 22 '26 07:01

Fausto R.


1 Answers

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.

like image 180
megabyte1024 Avatar answered Jan 24 '26 13:01

megabyte1024