title: Externs of constructed objects for Google's Closure Compiler
body: <p><strong>First off:</strong> I am aware of <a href="https://stackoverflow.com/questions/4267413/how-to-auto-generate-externs-for-the-google-closure-compiler">this SO question</a> and also the <a href="http://www.dotnetwise.com/Code/Externs/index.html" rel="nofollow noreferrer">externs extractor here</a>.</p>
  
  <p>I'm working on my first game project using <a href="http://threejs.org/" rel="nofollow noreferrer">ThreeJS</a>. Since I've built it in a modular manner, I intended to use <a href="https://developers.google.com/closure/compiler/" rel="nofollow noreferrer">Google's Closure Compiler</a> to pack my results in the end. A little test showed that compiling (using Advanced Optimizations) would also minify methods and properties of constructed objects, for example <code>THREE.Geometry</code> or <code>THREE.Color</code>.</p>
  
  <p>Checking the generated externs file, this is what I find on <code>THREE.Color</code> at line 78 (ThreeJS r60):</p>
  
  <pre><code>"Color": function () {},
  </code></pre>
  
  <p>Obviously it lacks methods and properties, so the Closure Compiler wouldn'nt know it's not supposed to rename these.</p>
  
  <p><strong>I had another solution</strong> which would be to define <em>exposures</em> in a separate file and compile it along with the sources. It works fine, but it's a lot of manual work to define each used method and property this way. Also this is just a hackish workaround. The Closure Compiler simply resorts to not renaming any occurrences of these names on objects at all.</p>
  
  <p>For example, all of these have the same effect:</p>
  
  <pre><code>/** @expose */
  THREE.Geometry.vertices;
  
  /** @expose */
  THREE.vertices;
  
  /** @expose */
  Object.vertices;
  
  window.vertices = function() {
      console.log("foo");
  };
  </code></pre>
  
  <p><code>window.vertices</code> will not be renamed. Consequentially this is not an ideal solution.</p>
  
  <p><strong>The actual question is:</strong> Is the Closure Compiler even capable of this? Or should I rather bake such dependencies into my compilation and have it rename all methods and properties I use?</p>