Open Huauauaa opened 2 years ago
class Singleton { constructor(name) { this.name = name; this.instance = null; } static getInstance(name) { if (!this.instance) { this.instance = new Singleton(name); } return this.instance; } }
var Singleton = function (name) { this.name = name; this.instance = null; }; Singleton.getInstance = function (name) { if (!this.instance) { this.instance = new Singleton(name); } return this.instance; };
单例
es5