class SingletonLogin{ constructor (name, password){ this.name = name this.password =password } static getInstance(name,password){ //判断是否已经被创建, 若创建则返回旧对象 if(!this.instance){ this.instance = new SingletonLogin(name,password); } return this.instance } } let obj1 = SingletonLogin.getInstance("zhangsan",'123'); let obj2 = SingletonLogin.getInstance("lisi",'234'); console.log(obj1 === obj2); console.log(obj1); console.log(obj2);