whitesiroi
whitesiroi

Reputation: 2833

.then() / .done() doesn't work as expected - jQuery

Here is an example:

function firstFun() {
  var dfd = new $.Deferred();

  return dfd.reject();
}

function secondFun() {
  console.log('in secondFun');
}

console.log('start');

firstFun().then(secondFun());

Nevertheless I return dfd.reject() the secondFun() is fired.

the same with firstFun().done(secondFun());

Upvotes: 2

Views: 396

Answers (1)

Cubed Eye
Cubed Eye

Reputation: 5631

Try firstFun().then(secondFun);

.then and .done expect function as parameters to be used as callbacks. But you're invoking secondFun instead of just passing it (hence actually passing undefined).

Upvotes: 11

Related Questions