# Reflection (js) getting class from companion object

**URL:** <https://discuss.kotlinlang.org/t/reflection-js-getting-class-from-companion-object/2588>\
**Category:** Support\
**Created:** [May 12, 2017, 5:33am UTC](https://discuss.kotlinlang.org/t/reflection-js-getting-class-from-companion-object/2588 "2017-05-12T05:33:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennyl](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@bennyl](https://discuss.kotlinlang.org/u/bennyl)\
**Post date:** [May 12, 2017, 5:33am UTC](https://discuss.kotlinlang.org/t/reflection-js-getting-class-from-companion-object/2588/1 "2017-05-12T05:33:26Z")

</div>

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:

```kotlin
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…
