i just started to learn coffeescript and it’s great, but it’s tricky..
i try to translate code, that worked in javascript to coffeescript
and i fail alot, in a link i posted 3 pastes
- js.js is original code that working
- cs.coffee is same version, but in coffeescript
- compiled.js translated by cs compiler version of js
in translated js i got an error of “String is not a function” somewhere in a lambda that returns to map
@is just shorthand forthis.So where your original js has:
your coffeescript should have
Where you have
$(this)in your original js, you still need$(this)in your coffeescript. Soor @input1.map(-> this.val().match(/\s+/g)).length not 0
should be:
I can’t offhand see any other issues – try it and let’s see if that gets it working, or if there are still errors.
[Edit]
There were other issues, largely related as mentioned to the
not 0and also to bracketing. Here’s a working (I think) coffeescript:It becomes:
Which looks about right.