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

边栏推荐
- Latex formula and table recognition
- Why is LNX of e equal to X
- 医学图像开源数据集汇总(二)
- latex公式及表格识别
- Implementation of simple floating frame in WindowManager
- 买的长期理财产品,可以转短吗?
- Learning Tai Chi Maker - esp8226 (XIII) OTA
- e的lnx为什么等于x
- Event registration Apache pulsar x kubesphere online meetup hot registration
- 5分钟,客服聊天处理技巧,炉火纯青
猜你喜欢

Servlet fast foundation building

PRCT-1400 : 未能执行 getcrshome解决方法

IDEA 无法保存设置 源根 D:XXXX在模块XXX中重复

L01_ How is an SQL query executed?

Netrca: an effective network fault cause localization

latex公式及表格识别

二十、处理器调度(RR时间片轮转,MLFQ多级反馈队列,CFS完全公平调度器,优先级翻转;多处理器调度)

顶刊TPAMI 2022!基于不同数据模态的行为识别:最新综述

Inspiration from reading CVPR 2022 target detection paper

编程题(持续更新)
随机推荐
Software system dependency analysis
Thinkphp5 multi language switching project practice
JCIM|药物发现中基于AI的蛋白质结构预测:影响和挑战
impdp导schema报ORA-31625异常处理
LeetCode: 240. Search 2D matrix II
Amazing tips for using live chat to drive business sales
R ellipse random point generation and drawing
threejs的点光源+环境光
Endgame P.O.O
Nlp-d59-nlp game D28 - I think it's OK - stage summary - mentality adjustment
达梦数据库如何定位锁等待问题解决方法
Go language project development practice directory
ssh远程免密登录
Cdga | how can we do well in data governance?
When should gridfs be used?
Algorithm -- find and maximum length k subsequence (kotlin)
使用Live Chat促進業務銷售的驚人技巧
R 椭圆随机点产生并画图
CDGA|到底怎么才能做好数据治理呢?
Weekly recommended short video: is the ultimate form of computing "meta universe"?