“Metody słabości JavaScript” Kod odpowiedzi

Metody słabości JavaScript

const weakMap = new WeakMap();
console.log(weakMap); // WeakMap {} 

let obj = {};

// adding object (element) to WeakMap
weakMap.set(obj, 'hello');

console.log(weakMap); // WeakMap {{} => "hello"}
// get the element of a WeakMap
console.log(weakMap.get(obj)); // hello
// check if an element is present in WeakMap
console.log(weakMap.has(obj)); // true
// delete the element of WeakMap
console.log(weakMap.delete(obj)); // true

console.log(weakMap); // WeakMap {}
SAMER SAEID

Metody słabości JavaScript

const weakMap = new WeakMap();
console.log(weakMap); // WeakMap {} 

let obj = {};

// adding object (element) to WeakMap
weakMap.set(obj, 'hello');

console.log(weakMap); // WeakMap {{} => "hello"}
// get the element of a WeakMap
console.log(weakMap.get(obj)); // hello
// check if an element is present in WeakMap
console.log(weakMap.has(obj)); // true
// delete the element of WeakMap
console.log(weakMap.delete(obj)); // true

console.log(weakMap); // WeakMap {}
SAMER SAEID

Odpowiedzi podobne do “Metody słabości JavaScript”

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu