单例模式
Posted lbcxq
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了单例模式相关的知识,希望对你有一定的参考价值。
var CreateDiv = function (html) this.html = html; this.init(); ; CreateDiv.prototype.init = function () var div = document.createElement(‘div‘); div.innerHTML = this.html; document.body.appendChild(div); ; var ProxySingletonCreateDiv = (function () var instance = null ; return function (html) if(!instance) instance = new CreateDiv(html) return instance )(); var a = new ProxySingletonCreateDiv("seven1") ; console.log(a); var b = new ProxySingletonCreateDiv("seven2") ; console.log(b);
以上是关于单例模式的主要内容,如果未能解决你的问题,请参考以下文章