Reflection (js) getting class from companion object


#1

Hello, Is there a way to get the class (KClass) that declared a companion object if I have an instance of the companion object?

Here is an example:

class Example {
  companion object {
    //...
  }
}

//somewhere else:
val x: Any = Example // assume I received it from somewhere and does not know it belongs to Example
val cls = declaringClassOf(x::class) 
println( cls.simpleName) // <-- should print Example

declaringClassOf is the function I am missing, x::class returns the companion class while I want a function that return the declaring class (Example in my case).
I am looking for a solution that works on the js platform and therefore reflection capabilities is somewhat limited…