Created
July 24, 2020 04:58
-
-
Save andrewborisov/4162e585aca96ef9366968be3f5495d7 to your computer and use it in GitHub Desktop.
Гист для статьи "Еще раз о паттернах проектирования в Javascript es6"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Singleton { | |
constructor(data) { | |
if (Singleton.instance) { | |
return Singleton.instance; | |
} | |
Singleton.instance = this; | |
this.data = data; | |
return this; | |
} | |
} | |
// Code for the testing | |
const testing = () => { | |
const a = new Singleton('test1'); | |
const b = new Singleton('test2'); | |
if (a === b) { | |
console.log('Singleton работает, один экземпляр'); | |
} | |
}; | |
testing(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment