当前位置:网站首页>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)

边栏推荐
- Grpc local test joint debugging tool bloomrpc
- 十大证券公司哪个佣金最低,最安全可靠?有知道的吗
- 算法--找到和最大的长度为 K 的子序列(Kotlin)
- 数组无缝滚动demo
- 正则匹配手机号
- Threejs MMD model loading + contour loading + animation loading + Audio loading + camera animation loading +ammojs loading gltf model loading +gltf reflection adjustment
- 带文字的seekbar : 自定义progressDrawable/thumb :解决显示不全
- 2021-08-17
- Codeforces Round #392 (Div. 2) D. Ability To Convert
- Turn to: CEO of Samsung Electronics: all decisions should start from recognizing yourself
猜你喜欢

Summary of medical image open source datasets (II)

PhpStrom代码格式化设置

Conseils étonnants pour promouvoir les ventes d'entreprise avec le chat en direct

使用Live Chat促進業務銷售的驚人技巧

如何让社交媒体成为跨境电商驱动力?这款独立站工具不能错过!

ssh远程免密登录

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

R 椭圆随机点产生并画图

二叉树第一部分

Event registration Apache pulsar x kubesphere online meetup hot registration
随机推荐
ThinkPHP5多语言切换项目实战
Handling method of Oracle data file header SCN inconsistency
算法---矩阵中战斗力最弱的 K 行(Kotlin)
Algorithm - the K row with the weakest combat power in the matrix (kotlin)
Baidu AI template for knowledge understanding
el-table表格的拖拽 sortablejs
ssh远程免密登录
达梦数据库如何定位锁等待问题解决方法
Servlet快速筑基
JCIM|药物发现中基于AI的蛋白质结构预测:影响和挑战
2021-08-17
el-table点击添加行样式
如何管理海量的网络基础设施?
Seekbar with text: customize progressdrawable/thumb: solve incomplete display
Oracle数据文件头SCN不一致处理方法
nVisual数字基础设施运营管理软件平台
实战剖析:app扫码登陆实现原理(app+网页端详细逻辑)附源码
Use of vim
PHP使用递归和非递归方式实现创建多级文件夹
e的lnx为什么等于x