class User { constructor(role, pages) { this.role = role this.pages = pages } static Factory(role) { switch (role) { case "superAdmin": return new User("superAdmin", ['home', 'news', 'user', 'right']) break; case "admin": return new User("admin", ['home', 'news', 'user']) break; case "editor": return new User("editor", ['home', 'news']) break; default: throw new Error('wrong para') break; } } }
let user=User.Factory('admin')