function bar(name) {
this.instance = null;
this.name = name
};
bar.prototype.getName = function() {
return this.name
};
bar.getInstance = function(name) {
if (!this.instance) {
this.instance = new bar(name)
}
return this.instance
};
var a = bar.getInstance('a');
var b = bar.getInstance('b');
function once(fn) {
var called = false
return function() {
if (!called) {
called = true
fn.apply(this, arguments)
}
}
}
function createModal(){
var div = document.createElement('div');
div.innerHTML = '弹窗';
document.body.appendChild(div);
return div
}
var modal = once(createModal)
modal()
console