简体   繁体   English

在Javascript中嵌入coffeescript…?

[英]Embedding coffeescript … in Javascript?

Within the current codebase of javascript code, I would like to be able to incrementally replace functions/blocks using cleaner and compact coffeescript, and add new code using coffeescript. 在当前的javascript代码代码库中,我希望能够使用更简洁的紧凑型coffeescript逐步替换函数/块,并使用coffeescript添加新代码。

  1. Is it a good practice? 这是一个好习惯吗? (In fact, shouldn't this be a default approach?) (实际上,这不是默认方法吗?)
  2. I need a utility to convert javascript with embedded coffeescript into javascript, and well integrated into node.js environment? 我需要一个实用程序来将带有嵌入式coffeescript的javascript转换为javascript,并很好地集成到node.js环境中?

Javascript到Coffee-script双向转换器

I am not exactly sure what you mean by "javascript with embedded coffeescript", but nonetheless, here is my advice: 我不确定“带嵌入式coffeescript的javascript”是什么意思,但是,我的建议是:

1) Use Grunt to compile your coffeescript into javascript whenever you save a file ( and also have Grunt do other sutff for you ) 1)每当您保存文件时,都可以使用Grunt将您的coffeescript编译为javascript(并让Grunt为您做其他的处理)

2) Do all new development in coffeescript. 2)在coffeescript中进行所有新开发。 Once you go coffeescript, you never want to go back. 一旦您完成了咖啡脚本,就再也不想回去了。 It's just better, and there really is no downside. 只是更好,而且确实没有不利之处。

If the objective is to use some language that is concise and to incrementally update your existing Javascript code to that language than Microsoft's TypeScript might be a better choice than CoffeeScript. 如果目标是使用一种简洁的语言,并将您现有的Javascript代码逐步更新为该语言,那么Microsoft的TypeScript可能比CoffeeScript更好。 Typecript lets you mix JavaScript and Typescript. Typecript使您可以混合使用JavaScript和Typescript。

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

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