Skip to content

realize lazyman by js (use settimeout (){fn,0})

Notifications You must be signed in to change notification settings

Wen-ace/lazyman

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

lazyman

use a array to simulate stacks

simple method / ********************************* / var tasks = []; function next() { console.log(tasks); var fn = tasks.shift(); fn && fn(); } function init() { var fn = (function () { return function () { setTimeout(function () { next(); }, 0) } })(); tasks.push(fn); next(); return this; } function first() { var fn = (function () { return function () { setTimeout(function () { console.log(1); next(); }, 1000); } })(); tasks.push(fn); return this; } function two() { var fn = (function () { return function () { setTimeout(function () { console.log(2); next(); }, 1000); } })(); tasks.push(fn); return this; }

init();
two();
first();

  / ******************************* /

About

realize lazyman by js (use settimeout (){fn,0})

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages