流星第三方脚本工作
问题描述:
我想添加第三方Javascript文件。流星第三方脚本工作
E.g.当我把它放在文件夹/public/test.js或/lib/test.js或/client/test.js
function testLoad(){
alert("something");
}
我看到剧本越来越加载,但是当我试图通过
运行它们if (Meteor.isClient) {
testLoad();
}
我收到以下错误
ReferenceError: testLoad is not defined
我缺少什么?
答
你应该把你的文件client/compatibility
:
Some JavaScript libraries only work when placed in the client/compatibility subdirectory. Files in this directory are executed without being wrapped in a new variable scope. This means that each top-level var defines a global variable. In addition, these files are executed before other client-side JavaScript files.
http://docs.meteor.com/#structuringyourapp
的问题是,function functionName(){ <code> }
不会是全局定义的函数(除非你把它放在client/compatibility
文件夹)。