Why does When.js promise.then skip a function?

384 Views Asked by At

Can someone explain why this prints in reverse order?

Code:

when('test')
  .then(function() {console.log('should be first');})
  .then(console.log('should be second'));

Output:

should be second
should be first

PS: I am using when.js version: [email protected]

1

There are 1 best solutions below

1
On BEST ANSWER

You're immediately executing the second console.log, and passing the return value to then. You need to pass functions to then.

You've effectively done this:

var x = console.log('should be second')

when('test')
  .then(function () { console.log('should be first'); })
  .then(x);