单例模式(改造)

/*
			单例改造
			1.需要instance 保存下来
			
			*/
			
			const singleTon=(function(){
				function Person(name,age,sex){
					this.name = name;
					this.age = age;
					this.sex = sex;
				}
				
				Person.prototype.say = function(){
					console.log('hello')
				}
				let instance = null;
				return function singleTon(...age){
					if(!instance) instance = new Person(...age)
					return instance
				}
				
			})()
			const p1 = singleTon('熊明',18,'男')
			const p2 = new singleTon('徐奥话',20,'女')
			console.log(p1,p2)
			console.log(p1==p2)

上一篇:Redis持久化方式


下一篇:第十七集:三大特性-封装