1,async await/promise的简单用例;
//简单例子;
function initProtoOfDailyPaln(proto){
proto.cancel = function cancel(){
//暂时不考虑取消正在进行的活动;
if(this.queue.length === 0){
console.log('计划队列里已无计划,恭喜完成了所有计划');
}else{
var plan = this.queue.pop();
console.log(plan);
}
return this;
};
proto.eat = function eat(type, duration, place, startTime){
//type would be lunch,breakfast,
duration = duration || 30;
place = place || 'at home';
startTime = startTime ? new Date(startTime) : null;
type = type || dessert;
//对象属性简写 duration;
var plan = {
duration,
startTime,
planName: 'eat '+ type,
detail: place
};
this.subscribe(plan);
return this;
};
//activity can