Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

superclass' methods not available

Tags:

sapui5

Most docs on the init method of UI5 components mention to call the superclass' init method when overwriting it:

sap.ui.commons.Button.prototype.init.apply(this, arguments); 

But this is not working. When debugging sap.ui.commonds.Button and analyzing its prototype, there's no init method present - so of course apply fails.

Am I doing anything wrong or is this a deprecated approach?

like image 436
Nico Hennrich Avatar asked Feb 14 '26 10:02

Nico Hennrich


1 Answers

From the UI5 documentation:

If you inherit from another control that has (or might get) an init() method, you need to explicitly call it...

Since the Button control has no init() function so far (but can exist in future versions) I would do it like this to be future safe:

 if (sap.ui.commons.Button.prototype.init) {   // check whether superclass has an init() method
  sap.ui.commons.Button.prototype.init.apply(this, arguments);  // call super.init()
}

Hope this helps you.

like image 156
Tim Gerlach Avatar answered Feb 17 '26 02:02

Tim Gerlach