Skip to content

Instantly share code, notes, and snippets.

@andrewborisov
Created July 24, 2020 04:58
Show Gist options
  • Save andrewborisov/4162e585aca96ef9366968be3f5495d7 to your computer and use it in GitHub Desktop.
Save andrewborisov/4162e585aca96ef9366968be3f5495d7 to your computer and use it in GitHub Desktop.
Гист для статьи "Еще раз о паттернах проектирования в Javascript es6"
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