为什么When.js承诺.然后跳过一个函数?

Ana*_*dis -1 javascript promise when-js

有人可以解释为什么这个以相反的顺序打印?

码:

when('test')
  .then(function() {console.log('should be first');})
  .then(console.log('should be second'));
Run Code Online (Sandbox Code Playgroud)

输出:

should be second
should be first
Run Code Online (Sandbox Code Playgroud)

PS:我使用的是when.js版本:when@3.4.3

mea*_*gar 5

您将立即执行第二个console.log,并将返回值传递给then.你需要传递函数then.

你有效地做到了这一点:

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

when('test')
  .then(function () { console.log('should be first'); })
  .then(x);
Run Code Online (Sandbox Code Playgroud)