1 Star 1 Fork 0

csq/design-patterns

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
singletonPatternClassTest.html 1.59 KB
一键复制 编辑 原始数据 按行查看 历史
csq 提交于 2023-08-25 17:37 +08:00 . 单例模式使用class语法处理
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./dist/idnex.js"></script>
<!-- 测试单例模式 -->
</head>
<body id="body-dom">
<button id="createAlert">创建弹窗</button>
<button id="removeAlert">移除弹窗</button>
</body>
<script src="./dist/SingletonPattern-class.js"></script>
<script lang="ts">
const singleton1 = Singleton.getInstance({ height: '200px', width: '200px', html: 'bbbb', style: { color: 'pink' } })
const singleton2 = Singleton.getInstance({ height: '200px', width: '200px', html: 'aaaa', style: { color: 'black' } })
console.log('singleton1', singleton1);
console.log('singleton2', singleton2);
// const createAlertBtn = document.getElementById('createAlert')
// const removeAlertBtn = document.getElementById('removeAlert')
// const bodyDom = document.getElementById('body-dom')
// let div
// createAlertBtn.onclick = function () {
// // 调用了两次方法,但是只创建了一个实例
// div = singletonCreateAlertMessage({ height: '200px', width: '200px', html: '123123', style: { color: 'red' } })
// const div1 = singletonCreateAlertMessage({ height: '200px', width: '200px', html: 'aaaaa', style: { color: 'green' } })
// console.log('div === div1', div === div1);
// bodyDom.appendChild(div)
// bodyDom.appendChild(div1)
// }
// removeAlertBtn.onclick = function () {
// bodyDom.removeChild(div)
// }
</script>
</html>
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
TypeScript
1
https://gitee.com/csq-cn/design-patterns.git
git@gitee.com:csq-cn/design-patterns.git
csq-cn
design-patterns
design-patterns
master

搜索帮助