SOURCE

class User {
    constructor(opt) {
        this.job = opt.job;
        this.method = opt.method;
    }

    static getInstance(role) {
        switch(role) {
            case 'master':
                return new User({job:'法师',method:['动感光波','小波']})
                break;
            case 'warrior':
                return new User({job:'战士',method:['小拳拳捶胸口','扫荡腿']})
                break;
            case 'tank':
                return new User({job:'坦克',method:['肉蛋冲击','无敌护盾']})
                break;    
            default:
                throw new Error('参数错误,可选:master、warrior、tank')
        }
    }
}

let master1 = User.getInstance('master')
console.log(master1)
let warrior1 = User.getInstance('warrior')
console.log(warrior1)
let tank1 = User.getInstance('tank')
console.log(tank1)
console 命令行工具 X clear

                    
>
console