简体   繁体   English

如何修复Javascript中的“未定义不是对象”错误

[英]How to fix “Undefined is not an object” error in Javascript

I am trying to use scripts in illustrator. 我正在尝试在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 当我尝试运行它时,我收到

Error 21: Undefined is not an object. 错误21:未定义不是对象。
Line 6 -> var Libraries = (function(libpath){" 第6行-> var库=(function(libpath){“

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. 或者我一般都不了解这个问题。

I expected it to import helloworld.jsx and hence be able to run the helloWorld function. 我希望它能够导入helloworld.jsx,因此能够运行helloWorld函数。 It threw up the error described above. 它引发了上述错误。

//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<c&&(!(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();

自从我做完这些东西以来,已经有很多月了……库不是一个需要libPath的函数,所以您需要调用

Libraries('c:\whereever').include('HellowWorld.jsx');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM