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);
原文:https://www.cnblogs.com/lbcxq/p/11436439.html