Singleton
by Artem
JavaScript
'use strict';
let Person = function(firstName) {
if (typeof Person.instance_ === 'object') {
return Person.instance_;
}
Person.instance_ = this;
this.firstName_ = firstName;
};
Person.prototype.getFirstName = function() {
return this.firstName_;
}
let a = new Person('vasya');
let b = new Person('petya');
console.log(a, b);