代码拉取完成,页面将自动刷新
A lightweight implementation of Deferred/Promise.
$ npm install deferred-lib
<script src="js/deferred.min.js"></script>
// Usage 1
// Declare the deferred instance and use it.
function countdown1() {
var deferred = new Deferred();
var i = 5;
var timer = setInterval(function () {
deferred.notify(i);
if (i-- === 0) {
deferred.resolve('Hi');
clearInterval(timer);
}
}, 300);
return deferred.promise();
}
countdown1().progress(function (step) {
console.log('countdown1', step);
}).done(function () {
console.log('countdown1 done');
});
// Usage 2
// Use `Deferred(fn)` and get the deferred instance with `this` context.
function countdown2() {
var self = this;
var i = 5;
var timer = setInterval(function () {
self.notify(i);
if (i-- === 0) {
self.resolve('Hi');
clearInterval(timer);
}
}, 300);
}
Deferred(countdown2).progress(function (step) {
console.log('countdown2', step);
}).done(function () {
console.log('countdown2 done');
});
See examples
directory for more usages.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型