Comments (1)
单例模式
既创建的对象只会存在一个,如果多次实例化,得到的依然是第一次实例化的对象。
function Base(){
// 判断是否存在实例
if (typeof Base.instance === 'object') {
return Base.instance;
}
// 缓存
Base.instance = this;
// 隐式返回this
}
// 使用
var base1 = new Base();
var base2 = new Base();
console.log(base1 instanceof Base); // true
console.log(base2 instanceof Base); //true
console.log(base2 === base1); // true
from houserqu.github.io.
Related Issues (19)
- how to handle error in async/await HOT 2
- 前端多页面应用开发脚手架 | Houser's Blog HOT 1
- 笔记-5 | Houser's Blog
- 阿里云日志服务配合Apache使用 | Houser's Blog
- 数据库 HOT 1
- Sequelize.js HOT 1
- Nginx HOT 5
- node HOT 6
- VScode
- 关于我 | Houser's Blog HOT 2
- 记录一次恢复 Mysql 中被 Update 操作覆盖的数据的过程 | Houser's Blog
- 欢迎访问我的 Wiki
- 技术栈 HOT 4
- Git HOT 4
- web 流程图 实现 HOT 1
- Mac 上使用 IE 内核浏览器
- 也许你并不需要 JS 库 HOT 1
- 常用 Linux 命令 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from houserqu.github.io.