Multiple Lines in Coffeescript Function

I have the following Coffeescript:

$ -> $('#new_event').submit -> $.post( $(this).attr('action') $(this).serialize() (data, textStatus, jqXHR) -> $('#target').html(data) ) return false 

And it translates as follows:

 $(function() { return $('#new_event').submit(function() { $.post($(this).attr('action'), $(this).serialize(), function(data, textStatus, jqXHR) { return $('#target').html(data); }); return false; }); }); 

So far so good. However, how to add another line to submit? For instance:

 $ -> $('#new_event').submit -> test = $(this).serialize() $.post( $(this).attr('action') $(this).serialize() (data, textStatus, jqXHR) -> $('#target').html(data) ) return false 

This gives an unexpected INDENT error. I can’t understand what I’m missing here ...

Thanks, Dani.

+4
source share
1 answer

Most likely you mixed spaces and tabs for indentation. Coffeescript don't like it.

And by the way, you can write @ instead of this .

+5
source

Source: https://habr.com/ru/post/1379431/


All Articles