Js 工厂模式

 1     function CreatObject(name, age) {
 2         let obj = {}
 3         obj.name = name
 4         obj.age = age
 5         obj.run = function () {
 6             return this.name + this.age + 'run>>>>'
 7         }
 8         return obj
 9     }
10     box = CreatObject ('xiaowang1', 18)
11     box2 = CreatObject ('xiaowang2', 34)
12     console.log(box.run())
13     console.log(box)

 

posted @ 2020-07-29 10:13  Salvater  阅读(74)  评论(0编辑  收藏  举报