title: How to fix "Undefined is not an object" error in Javascript
body: <p>I am trying to use scripts in illustrator. Some of these require being able to import other scripts so I found the below code. When I try to run it I receive </p>
  
  <blockquote>
    <p>Error 21: Undefined is not an object.<br>
    Line 6 -> var Libraries = (function(libpath){"</p>
  </blockquote>
  
  <p>I have looked through other answers and it seems the issue is that "Libraries" (?) is undefined, and that I ought to define it first. Sadly I don't know what it ought to be defined as. Or I don't understand the problem in general.</p>
  
  <p>I expected it to import helloworld.jsx and hence be able to run the helloWorld function. It threw up the error described above.</p>
  
  <pre class="lang-js prettyprint-override"><code>//Library importing function from https://gist.github.com/jasonrhodes/5286526
  
  // indexOf polyfill from https://gist.github.com/atk/1034425
  [].indexOf||(Array.prototype.indexOf=function(a,b,c){for(c=this.length,b=(c+~~b)%c;b&lt;c&amp;&amp;(!(b in this)||this[b]!==a);b++);return b^c?b:-1;});
  
  var Libraries = (function(libPath) {
    return {
      include: function(path) {
        if (!path.match(/\.jsx$/i)) {
          path = path + ".jsx";
        }
        return $.evalFile(libPath + path);
      }
    };
  })($.fileName.split("/").splice(0,$.fileName.split("/").indexOf("adobe_scripts") + 1).join("/") + "/lib/");
  
  Libraries.include("HelloWorld.jsx");
  helloWorld();
  </code></pre>