💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 代理模式 给某个流程添加一个中间人 ## 示例 ```js // 创建一个班长 var monitor = { homeworks: [] }; // 老师构造函数 function Teacher(name) { this.teacherName = name; this.homeworks = [] } // 收一份作业 monitor.add = function(homework){ this.homeworks.push(homework) } // 交作业 monitor.send = function(teacher) { teacher.homeworks = this.homeworks; this.homeworks = []; console.log('已经把作业交给 ' + teacher.teacherName + ' 老师'); } monitor.add('张三的作业'); monitor.add('李四的作业'); var niu = new Teacher('牛老师') monitor.send(niu); console.log(niu.homeworks);