Сообщение от Раед
|
как обычно, через замыкание
var human = (function () {
var name;
var prototype = {}
prototype.getName
prototype.getName = function (str) {
if (str) name = str
return name
}
function constructor(data) {
name
}
constructor.prototype = prototype
return constructor
}())
var h1 = new human
h1.getName('Vasia')
var h2 = new human
h2.getName('Petia')
|
И каков по вашему результат?
Если бы всё было так просто, я бы не спрашивал, после выполнения этого кода, стало так:
h1.getName() // Petia
h2.getName() // Petia
Мне нужно чтобы
name был уникальным для каждого экземпляра.