当前位置:网站首页>JS singleton mode
JS singleton mode
2022-06-24 09:51:00 【Time202051】
class LoginForm {
constructor() {
this.state = 'hide'
}
show() {
if (this.state == "show") {
return
}
this.state = 'show'
console.log(" The login box displays ");
}
hide() {
if (this.state === 'hide') {
return
}
this.state = 'hide'
console.log(" The login box is hidden ");
}
}
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)

边栏推荐
- 桌面软件开发框架大赏
- 操作符详解
- Tnsnames Ora file configuration
- CF566E-Restoring Map【bitset】
- 【自定义Endpoint 及实现原理】
- In depth study paper reading target detection (VII) Chinese English Bilingual Edition: yolov4 optimal speed and accuracy of object detection
- 数组无缝滚动demo
- SQL-统计连续N天登陆的用户
- LeetCode: 137. 只出现一次的数字 II
- Software system dependency analysis
猜你喜欢

二叉樹第一部分

June 13-19, 2022 AI industry weekly (issue 102): career development

Prct-1400: failed to execute getcrshome resolution

impdp导schema报ORA-31625异常处理

谈谈数字化转型晓知识

e的lnx为什么等于x

Top issue tpami 2022! Behavior recognition based on different data modes: a recent review

Servlet fast foundation building

indexedDB本地存储,首页优化

R 椭圆随机点产生并画图
随机推荐
SSH Remote Password free login
grpc本地测试联调工具BloomRPC
正则匹配邮箱
ApplicationContextInitializer的三种使用方法
How to locate lock waiting in Dameng database
Top issue tpami 2022! Behavior recognition based on different data modes: a recent review
字节跳动-面试官: 谈下音视频同步原理,音频和视频能绝对同步吗?
有关二叉树 的基本操作
Latex formula and table recognition
JCIM|药物发现中基于AI的蛋白质结构预测:影响和挑战
Five heart matchmaker
Oracle数据库监听文件配置
About thinkphp5, use the model save() to update the data prompt method not exist:think\db\query- & gt; Error reporting solution
NVIDIA's CVPR 2022 oral is on fire! 2D images become realistic 3D objects in seconds! Here comes the virtual jazz band!
Oracle database listening file configuration
转:三星电子CEO:一切决策都要从认清自己开始
vim的使用
Reasons for the failure of digital transformation and the way to success
P6117-[joi 2019 final] greedy
GIS实战应用案例100篇(十四)-ArcGIS属性连接和使用Excel的问题