概念:单例,指的就是只有一个实例的对象
var singleton = {
name: 'singleton',
method: () => {}
}
模块模式通过为单例添加私有变量和特权方法使其得到增强
var singleton = () => {
var privateValue = 1
function privateFunc() {
return privateValue
}
}
var singleton = {
name: 'singleton',
method: () => {}
}
var singleton = () => {
var privateValue = 1
function privateFunc() {
return privateValue
}
}