js任务链
var TASK_SYNC = 0; var TASK_ASYNC = 1; function Animation(){ this.taskQueue = []; } Animation.prototype._add = function(task,type){ this.taskQueue.push({ taskFn: task, type: type }) return this; } Animation.prototype._runTask = function(){ if(this.taskQueue.length){ for(key in this.taskQueue){ this.taskQueue[key].taskFn(); } } } Animation.prototype.start = function(){ this._runTask(); } Animation.prototype.say = function(){ var taskFn = function(){ console.log('say fn'); } var type = TASK_SYNC; return this._add(taskFn,type) } Animation.prototype.run = function(){ var taskFn = function(){ console.log('run fn'); } var type = TASK_SYNC; return this._add(taskFn,type) } var animation = new Animation(); animation.say().run().start();