当前位置:网站首页>js单例模式
js单例模式
2022-06-24 09:32:00 【Time202051】
class LoginForm {
constructor() {
this.state = 'hide'
}
show() {
if (this.state == "show") {
return
}
this.state = 'show'
console.log("登录框显示");
}
hide() {
if (this.state === 'hide') {
return
}
this.state = 'hide'
console.log("登录框隐藏");
}
}
LoginForm.getInstance = (() => {
let instance
return () => {
if (!instance) {
instance = new LoginForm()
}
return instance
}
})()
let login1 = LoginForm.getInstance()
login1.show()
let login2 = LoginForm.getInstance()
login2.hide()
console.log(login1 === login2)

边栏推荐
- 最新Windows下Go语言开发环境搭建+GoLand配置
- 谈谈数字化转型晓知识
- 针对《VPP实现策略路由》的修正
- Niuke network realizes simple calculator function
- Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
- php单例模式详解
- 20、 Processor scheduling (RR time slice rotation, mlfq multi-level feedback queue, CFS fully fair scheduler, priority reversal; multiprocessor scheduling)
- ggplot2颜色设置总结
- [Eureka source code analysis]
- 实战剖析:app扫码登陆实现原理(app+网页端详细逻辑)附源码
猜你喜欢
随机推荐
In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection
Grpc local test joint debugging tool bloomrpc
Inspiration from reading CVPR 2022 target detection paper
Analysis of 43 cases of MATLAB neural network: Chapter 32 time series prediction of wavelet neural network - short-term traffic flow prediction
Threejs point light + ambient light
五心红娘
Seekbar with text: customize progressdrawable/thumb: solve incomplete display
桌面软件开发框架大赏
threejs的点光源+环境光
PostgreSQL
Zero foundation self-study SQL course | syntax sequence and execution sequence of SQL statements
Netrca: an effective network fault cause localization
nVisual数字基础设施运营管理软件平台
Turn to: CEO of Samsung Electronics: all decisions should start from recognizing yourself
居家办公如何管理数据中心网络基础设施?
如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!
可直接套用的Go编码规范
文献调研报告
Go 语言项目开发实战目录
Oracle查看数据文件头SCN信息








