S
S
Stanislav2015-08-18 22:22:59
CoffeeScript
Stanislav, 2015-08-18 22:22:59

How to convert existing js function to coffeescript?

Today I decided to try to work with coffeescript and a plug appeared, I don’t understand how to write this function on coffee?

function onError(error) {
  if (error.syscall !== 'listen') {
    throw error;
  }

  // handle specific listen errors with friendly messages
  switch (error.code) {
    case 'EACCES':
      console.error('Port ' + port + ' requires elevated privileges');
      process.exit(1);
      break;
    case 'EADDRINUSE':
      console.error('Port ' + port + ' is already in use');
      process.exit(1);
      break;
    default:
      throw error;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-08-18
@ms-dred

onError = (error) ->
  throw error if error.syscall isnt 'listen'

  # handle specific listen errors with friendly messages
  switch error.code
    when 'EACCES'
      console.error 'Port ' + port + ' requires elevated privileges'
      process.exit 1
    when 'EADDRINUSE'
      console.error 'Port ' + port + ' is already in use'
      process.exit 1
    else
      throw error

js2.coffee

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question