有没有清除.thenJavaScript Promise实例的方法?
我在QUnit上编写了一个JavaScript测试框架.框架通过在a中运行每个框架来同步运行测试Promise.(抱歉这个代码块的长度.我尽可能地评论它,所以感觉不那么乏味.)
/* Promise extension -- used for easily making an async step with a
timeout without the Promise knowing anything about the function
it's waiting on */
$$.extend(Promise, {
asyncTimeout: function (timeToLive, errorMessage) {
var error = new Error(errorMessage || "Operation timed out.");
var res, // resolve()
rej, // reject()
t, // timeout instance
rst, // reset timeout function
p, // the promise instance
at; // the returned asyncTimeout instance
function …Run Code Online (Sandbox Code Playgroud)