简体   繁体   English

如何在CoffeeScript中导入javascript库?

[英]How can I import a javascript library in CoffeeScript?

When I am loading my page I include a javascript library that is used to create graphs with the Google api. 当我加载我的页面时,我添加了一个javascript库,用于使用Google api创建图形。 I am handling this with CoffeeScript in the front end. 我正在使用前端的CoffeeScript处理这个问题。 According to the tutorial I am initiating the library like: data = new google.visualization.DataTable(); 根据教程,我正在启动库,如: data = new google.visualization.DataTable(); .

When I am parsing my produced JS code from CoffeeScript with JSHint I am getting an error that google is not defined. 当我使用JSHint从CoffeeScript解析我生成的JS代码时,我收到一个错误,谷歌没有定义。 How can I show to the parser that the library is actually loaded and the object exists? 如何向解析器显示实际加载库并且对象存在?

data = new google.visualization.DataTable();

PROBLEM:
'google' is not defined.

I have tried to call it from the window object like 我试图从窗口对象中调用它

data = new window.google.visualization.DataTable();

and it stopped complaining. 它停止了抱怨。

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

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