13

I am wondering how to get the object type of a SAPUI5 Javascript object at runtime. I can check if the object is of a particular type like so:

myObj instanceof sap.m.List

I'm looking for the equivalent of .getClass() in the Java world. I've tried a few approaches described on various other SO threads such as How do I get the name of an objects type in Javascript

There doesn't seem to be a standard approach, and none I've tried seem to work for UI5. This isn't causing me a problem but debugging in dev tools with my Java head on it would be nice to get the object type and therefore know what methods I can call.

Cheers, Gregor

Community
  • 1
  • 1
gregor
  • 189
  • 1
  • 3
  • 9
  • you can use `sap.ui.base.Object isA` if your objet inherit from `sap.ui.base.Object` https://sapui5.hana.ondemand.com/sdk/#/api/sap.ui.base.Object%23methods/isA – depth1 Dec 27 '22 at 11:50

2 Answers2

33

There's a metadata mechanism:

oControl = sap.ui.getCore().byId('<your control id>');
sType = oControl.getMetadata().getName();

In fact the object returned from sap.ui.core.Element#getMetadata contains a whole heap of introspection goodness.

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
qmacro
  • 3,025
  • 23
  • 33
-1

You can also try as:

sap.ui.getCore().byId("<your ID :D>").__proto__

This will give all list of function and operation. Generally I do in in console to get an idea about what are other things can be done.

Ank
  • 402
  • 5
  • 12
  • I think it would be more helpful for the OP and further visitors, when you add some explaination to your intension. – Reporter Sep 03 '14 at 09:09
  • Tried to add an Image but , found out that required a user to have at least 10 points and i was short of it :( – Ank Sep 03 '14 at 10:26
  • We are not allowed to use any properties that starts with underline, they are private variables for SAPUI5 library and they are free to change them in their updates, then if you use them your code can be unreliable as soon as you update the UI5 library. – MJBZA Apr 02 '19 at 09:06