'superclass' methods not available
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?
Solution 1:[1]
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.
Solution 2:[2]
Thanks to the commit e9fb3c1 by Jonathan Brink, this is no longer an issue since OpenUI5 version 1.54.0 (SAPUI5 1.54.2). Checking the existence of the init, onBeforeRendering, onAfterRendering, and exit in the superclass is not required anymore.
init: function() {
MyRequiredSuperControl.prototype.init.apply(this, arguments);
// ...
},
Simply call init.apply without if.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tim Gerlach |
| Solution 2 |
