企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
<hr> <div id="div1"><h3> <font color=red> 工厂模式 </font> <h3></div> 构造函数和创建者分离,==对new操作进行封装== 符合开放封闭原则 ```javascript class Creator { create(name) { return new Animal(name) } } class Animal { constructor(name) { this.name = name } } var creator = new Creator() var duck = creator.create('Duck') console.log(duck.name) // Duck ```