繁体   English   中英

如何在CoffeeScript中编写这个简单的JavaScript代码?

[英]How to write this simple javascript code in CoffeeScript?

我想在javascript中使用此代码:

beforeNode = children[  children.length -1 ]

使用coffeecript中的这段代码:

beforeNode = children[  children.length -1 ]

coffescript生成:

beforeNode = children[children.length(-1)];

如何在coffescript中编写源代码以生成预期的javascript代码?

谢谢

不要使用空间!

// coffeescript
beforeNode = children[children.length-1]

或者在-每一侧使用一个空间-

// coffeescript
beforeNode = children[children.length - 1]

结果是

// js
var beforeNode;

beforeNode = children[children.length - 1];

或者使用两个空格!

# coffeescript
beforeNode = children[children.length - 1]

结果是

// javascript
var beforeNode;

beforeNode = children[children.length - 1];

暂无
暂无

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

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