TGViewer
JavaScript test JavaScript test @js_test · 9.68K subscribers
Post #4952 727
❗️Что будет на выходе?

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);

Ответ: [true, undefined, 2]

JavaScript test | #JavaScript
More from @js_test
  1. Oct 15, 2026❗️Что будет на выходе: try { try { // Creating a custom error type class CustomError exten…
  2. Oct 15, 2026❗️Что будет на выходе: const createMathOps = (base) => { return { add: (x) => base + x, mu…
  3. Oct 15, 2026❗️Что будет на выходе: const team = { name: 'Eagles', players: ['Smith', 'Johnson', 'Willi…
  4. Oct 14, 2026❗️Что будет на выходе: function processData({ a = 10, b = 20 } = { a: 30 }) { console.log(…
  5. Oct 14, 2026Как платить за границей и за зарубежные сервисы в 2026 году? Можно переплачивать посредник…
  6. Oct 14, 2026❗️Что будет на выходе: const person = { name: 'Alice', greet() { return `Hello, I'm ${this…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →