应该如何在 Spine 应用程序中同时使用 JavaScript 和 CoffeeScript?

发布于 2024-12-27 18:49:43 字数 354 浏览 3 评论 0原文

我现在正在研究 Spine、Hem、CoffeeScript 等,努力构建一个基于浏览器的应用程序。我想在应用程序中使用 JavaScript 图形库,我很确定它不是用 CoffeeScript 编写的(这重要吗?),所以我想知道如何在我的应用程序中混合 CoffeeScript 和 JavaScript应用程序...是不是就像将两者混合并让 Hem(这实际上触发 CoffeeScript 编译为 JavaScript,对吧?)在从 CoffeeScript 编译为 JavaScript 的过程中解决问题一样简单?或者在 JavaScript 中混合时我需要在 CoffeeScript 中使用特殊标签?

我在谷歌上搜索了一些此类事情的例子,但无济于事......请指教。

I'm just now wrapping my head around Spine, Hem, CoffeeScript, etc. in an effort to build a browser-based application. I'm wanting to use a JavaScript graphing library in the application that I'm pretty sure isn't written in CoffeeScript (does that matter?), so I'm wondering how I'd go about mixing both CoffeeScript and JavaScript in my application... is it as simple as just mixing the two and letting Hem (which is what actually triggers the CoffeeScript to get compiled to JavaScript, right?) figure things out during compilation from CoffeeScript to JavaScript? Or is it something where I need to use special tags in my CoffeeScript when mixing in JavaScript?

I've Googled around for some examples of such a thing but to no avail... please advise.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心房的律动 2025-01-03 18:49:43

应该没有问题。 Coffeescript 编译为 JavaScript(并且以比 GWT 更直接的方式)。浏览器看到的只是 JavaScript。

您可以从 Coffeescript 调用 Javascript,反之亦然。

不要将相同的内容混合在一个文件中(有一些 .coffee 和一些 .js 文件)。

确保您了解 Coffeescript 如何(默认情况下)编译成包装在其自己范围内的模块,以及如何在需要时从中导出符号。

我想在应用程序中使用 JavaScript 图形库,我很确定该库不是用 CoffeeScript 编写的(这重要吗?)

不,一点也不重要。您可以从 CoffeeScript 调用该库,就像从其他 JavaScript 调用该库一样简单。

弄清楚从 CoffeeScript 到 JavaScript 的编译过程中的情况?

当您编译 CoffeeScript 时,它不会检查它调用的函数是否存在(这在运行时发生)。因此编译器只查看 .coffee 文件,不需要关心项目中的其他文件。

There should not be a problem. Coffeescript compiles down to JavaScript (and in a much more straight-forward way then, say, GWT). What the browser will see is just JavaScript.

You can just call Javascript from Coffeescript and vice-versa.

Do not mix the same in one file (have some .coffee and some .js files).

Make sure you understand how Coffeescript compiles (by default) into modules wrapped into their own scopes, and how to export symbols from them if needed.

I'm wanting to use a JavaScript graphing library in the application that I'm pretty sure isn't written in CoffeeScript (does that matter?)

Nope, does not matter at all. You can call that library from CoffeeScript just as easily as you can from other JavaScript.

figure things out during compilation from CoffeeScript to JavaScript?

When you compile CoffeeScript, it does not check if functions that it calls exist or not (that happens at run-time). So the compiler only looks at the .coffee files, and does not need to care about the other files in your project.

物价感观 2025-01-03 18:49:43

当你想将js插入cs时,首先使用unquote“`”来包装你的js代码,如下所示:

`var ajax=new Ajax();`
do ajax.send 

但这不是一个好的做法。

第二:
有很多库可以让您只编写 .coffee 但为客户端编写服务 .js 文件。继续 https://github.com/jashkenas/coffee-script/wiki/Build-tools 来找出答案。

first use unquote "`" to wrap your js code when your want to insert js to cs,like this:

`var ajax=new Ajax();`
do ajax.send 

but this is not a good practice.

second:
there a lot of libs which let you write .coffee only but service .js file for client.go ahead https://github.com/jashkenas/coffee-script/wiki/Build-tools to find out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文