<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
</body>
<script>
var qichuang = {
execute:function () {
console.log("起床了")
}
}
var zaofan ={
execute:function () {
console.log("吃早餐")
}
}
var shangban = {
execute:function () {
console.log("上班挤地铁")
}
}
var kaihui = {
execute:function () {
console.log("开会讨论需求")
}
}
var daqiu = {
execute:function () {
console.log("打球")
}
}
var shuijiao = {
execute:function () {
console.log("睡觉了")
}
}
var shenghuo = {
commands : [qichuang,zaofan,daqiu,shuijiao],
execute : function () {
//console.log(this);
//console.log(this.commands);
for(var i=0;i<this.commands.length;i++){
this.commands[i].execute()
}
}
}
var gongzuo = {
//命令
commands :[shangban,kaihui,zaofan],
//执行
execute : function () {
for(var i=0;i<this.commands.length;i++){
this.commands[i].execute()
}
}
}
//整合组合执行所有的任务
var people = {
commands : [shenghuo,gongzuo],
execute : function () {
for(var i=0;i<this.commands.length;i++){
// console.log(this);
this.commands[i].execute()
}
}
}
people.execute();
</script>
</html>