Skip to content

[软技能] 第99天 你有用过单例模式吗?主要运用场景有哪些? #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
haizhilin2013 opened this issue Jul 23, 2019 · 5 comments
Labels
软技能 软技能

Comments

@haizhilin2013
Copy link
Collaborator

第99天 你有用过单例模式吗?主要运用场景有哪些?

@haizhilin2013 haizhilin2013 added the 软技能 软技能 label Jul 23, 2019
@ghost
Copy link

ghost commented Jul 24, 2019

写过用单例模式的框架。ionjs-dev/ionjs

@l8888888
Copy link

var A;
(function(name){
var instance;
A = function(name){
if(instance){
return instance
}
//赋值给私有变量
instance = this
//自身属性
this.name = name
}
}())

@forever-z-133
Copy link

https://www.cnblogs.com/restartyang/articles/7770856.html
相比引入共同的实例对象,单例模式在需要的时候才 new 会更节约内存。

@xiejunping
Copy link

mysql数据库连接就是单例模式,好控制,快速响应

@lizhesystem
Copy link

一个类只能初始化一个实例, 例如jqeury的$,vuex里的store的实现都是单例模式。保证对象的唯一性
符合单一职责原则,只能实例化唯一的对象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
软技能 软技能
Projects
None yet
Development

No branches or pull requests

5 participants