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

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

  •  23-06-2022
  •  | 
  •  

문제

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?

도움이 되었습니까?

해결책

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!");
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top