(function (win) {
function _lazyMan (name) {
var _this = this;
this.name = name;
this.queue = [];
this.queue.push(() => {
console.log('Init LazyMan ' + this.name);
_this.next();
});
setTimeout(function () {
_this.next();
})
}
_lazyMan.prototype.next = function () {
var fn = this.queue.shift();
typeof fn === 'function' && fn();
};
_lazyMan.prototype.sleep = function(time) {
var _this = this;
this.queue.push(function () {
setTimeout(function () {
console.log('LazyMan sleep ' + time + 's');
_this.next();
}, time * 1000);
});
return this;
};
_lazyMan.prototype.run = function(str) {
var _this = this;
this.queue.push(function() {
console.log('run ' + str);
_this.next();
});
return this;
}
function LazyMan (name) {
return new _lazyMan(name);
}
win.LazyMan = LazyMan;
}(window));
LazyMan('哈哈').sleep(4).run('test1').run('test2').run('test3');
LazyMan
?著作權歸作者所有,轉載或內容合作請聯系作者
- 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來奋姿,“玉大人锄开,你說我怎么就攤上這事〕剖” “怎么了萍悴?”我有些...
- 正文 為了忘掉前任撕予,我火速辦了婚禮,結果婚禮上蜈首,老公的妹妹穿的比我還像新娘实抡。我一直安慰自己欠母,他們只是感情好,可當我...
- 文/花漫 我一把揭開白布吆寨。 她就那樣靜靜地躺著赏淌,像睡著了一般。 火紅的嫁衣襯著肌膚如雪啄清。 梳的紋絲不亂的頭發(fā)上六水,一...
- 文/蒼蘭香墨 我猛地睜開眼计露,長吁一口氣:“原來是場噩夢啊……” “哼博脑!你這毒婦竟也來了?” 一聲冷哼從身側響起票罐,我...
- 正文 年R本政府宣布,位于F島的核電站狸演,受9級特大地震影響言蛇,放射性物質發(fā)生泄漏。R本人自食惡果不足惜宵距,卻給世界環(huán)境...
- 文/蒙蒙 一腊尚、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧满哪,春花似錦婿斥、人聲如沸劝篷。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽携龟。三九已至兔跌,卻和暖如春勘高,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背坟桅。 一陣腳步聲響...