3

for example

child.stdout.on \data (buffer) -> 
   result.stdout += buffer

-->

child.stdout.on('data', function(buffer){
  return result.stdout += buffer;
});

and I need it without return. In F# I can add |> ignore how can I handle it in livescript?

cnd
  • 32,616
  • 62
  • 183
  • 313
  • i'm curious why you need to have no return clause,as you can just ignore the result of the function call ? – lud Jun 10 '13 at 20:59
  • 1
    @niahoo If the last expression is a loop, it will create an array with all the elements and return it. This may be expensive. With `!->` it won’t create the array. –  Apr 30 '14 at 18:26

1 Answers1

4

You can prepend an ! to the definition of the function:

!(buffer) -> result.stdout += buffer

Alternatively, return void

child.stdout.on \data (buffer) -> 
   result.stdout += buffer
   void

In JavaScript, when you return undefined (void), it is the same as not returning anything.

MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
  • You can just put `return` instead of `void`. I'm not sure what's best practice, but `return` lets you return nothing in the middle of a function: `return if something` – Farzher Jan 13 '14 at 19:57