angelcervera
angelcervera

Reputation: 4177

How to write this simple javascript code in CoffeeScript?

I want this code in javascript:

beforeNode = children[  children.length -1 ]

With this fragment of code in coffeecript:

beforeNode = children[  children.length -1 ]

coffescript generate:

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

How can I write source in coffescript to generate expected javascript code?

Thanks

Upvotes: 0

Views: 93

Answers (2)

maček
maček

Reputation: 77778

Don't use a space!

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

Or use a space on each side of the -

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

Results in

// js
var beforeNode;

beforeNode = children[children.length - 1];

Upvotes: 2

zackdever
zackdever

Reputation: 1642

Or use two spaces!

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

Results in

// javascript
var beforeNode;

beforeNode = children[children.length - 1];

Upvotes: 0

Related Questions