LiveScript - How do I use the backcall operator when there are multiple callbacks?

StackOverflow https://stackoverflow.com/questions/18123457

  •  23-06-2022
  •  | 
  •  

Question

For example:

$.get('/path/to/api').then(
  function(data) {
    alert( "$.get succeeded" );
  }, function(error) {
    alert( "$.get failed!" );
  }
);

Is it possible to apply the backcall operator on both callbacks?

Était-ce utile?

La solution

You can only use one function with the backcall, but what you can do is use a backcall, and supply the other function normally (note the use of the _ as a placeholder to denote where the backcall function should go in the arguments) - eg.

data <- $.get '/path/to/api' .then _, -> alert "$.get failed!"
alert "$.get succeeded"

compiles to:

$.get('/path/to/api').then(function(data){
  return alert("$.get succeeded");
}, function(){
  return alert("$.get failed!");
});
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top