0

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

2 Answers 2

2

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];
Sign up to request clarification or add additional context in comments.

2 Comments

I would prefer instead to use a space between - and 1... i.e., beforeNode = children[children.length - 1].
@GauthamBadhrinathan updated answer to show this is possible too
0

Or use two spaces!

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

Results in

// javascript
var beforeNode;

beforeNode = children[children.length - 1];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.