tgoop.com/javascript/2244
Create:
Last Update:
Last Update:
CHALLENGE
const privateData = new WeakMap();
function Person(name) {
privateData.set(this, { name, secretCount: 0 });
this.greet = function() {
const data = privateData.get(this);
data.secretCount++;
return `Hello, my name is ${data.name}`;
};
this.getSecretCount = function() {
return privateData.get(this).secretCount;
};
}
const alice = new Person('Alice');
alice.greet();
alice.greet();
const result = [
privateData.has(alice),
alice.name,
alice.getSecretCount()
];
console.log(result);
BY JavaScript
Share with your friend now:
tgoop.com/javascript/2244