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?

Was it helpful?

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!");
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top