Skip to content

Latest commit

 

History

History
15 lines (12 loc) · 361 Bytes

单例模式.md

File metadata and controls

15 lines (12 loc) · 361 Bytes

单例模式

单例的核心就是判断有没有实例了,有实例就返回实例,没有就创建,下面是最简单的栗子:

var instance = null
var getInstance = function(arg) {
if (!instance) {
    instance = arg
}
return instance
}

var a = getInstance('a')
var b = getInstance('b')
console.log(a===b)