2014-10-01 89 views
0

我想添加第三方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

我缺少什麼?

回答

2

你應該把你的文件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文件夾)。