//定义篮球类
let Baseketball = function(){
this.info = “篮球”;
}
Baseketball.prototype = {
getRuler:function () {
console.log(“篮球需要5个人”);
}
}
//定义一个足球类
let Football = function(){
this.info = “足球”;
}
Football.prototype ={
getRuler:function () {
console.log(“需要好多人”);
}
}
//定义一个运动工厂类
let Factory = function(type){
switch (type){
case “base”:
return new Baseketball();
case “foot”:
return new Football();
}
}
//实例化运动工厂
let b = new Factory(“base”);
let f = new Factory(“foot”);
b.getRuler();
console.log(b.info);
f.getRuler();
console.log(f.info);