title: How to get source code location from ES6 JavaScript class instance?
body: <p>I would like to generate some code from my object tree. In order to generate the required import statements, I need to find out the source code location for a given class from a class instance.</p>
  
  <p>I am already able to get the expected name <code>MyClass</code> with </p>
  
  <pre><code>var name = instance.constructor.name;
  </code></pre>
  
  <p>but not the source code location </p>
  
  <pre><code>'/src/package/myClass.js'
  </code></pre>
  
  <p>=>How to do so? </p>
  
  <p>For Java it would work like described here:</p>
  
  <p><a href="https://stackoverflow.com/questions/227486/find-where-java-class-is-loaded-from">Find where java class is loaded from</a></p>
  
  <p>If I inspect the constructor in Chrome developer tools with dir(constructor), I can see some property</p>
  
  <pre><code>[[FunctionLocation]]: myClass.js:3
  </code></pre>
  
  <p>and if I hover over it, I can see the wanted path. How can I get that property programmatically?</p>
  
  <p><a href="https://i.stack.imgur.com/09nSb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/09nSb.png" alt="enter image description here"></a></p>
  
  <p><strong>Edit</strong></p>
  
  <p>Just found that [[FunctionLocation]] is not accessible:</p>
  
  <p><a href="https://stackoverflow.com/questions/41146373/access-function-location-programmatically">Access function location programmatically</a></p>