您能否在下面的代码中阐明为什么在将对象添加到 WeakMaps 时使用布尔值。我知道 set 需要两个(键和值)参数。布尔值也会打印在控制台中……这是我的疑问……</p>
提前致谢。
const book1 = { title: 'Pride and Prejudice', author: 'Jane Austen' };
const book2 = { title: 'The Catcher in the Rye', author: 'J.D. Salinger' };
const book3 = { title: 'Gulliver\'s Travels', author: 'Jonathan Swift' };
const library = new WeakMap();
library.set(book1, true);
library.set(book2, false);
library.set(book3, true);
console.log(library);
WeakMap {Object {title: 'Pride and Prejudice', author: 'Jane Austen'} => true, Object {title: 'The Catcher in the Rye', author: 'J.D. Salinger'} => false, Object {title: 'Gulliver\'s Travels', author: 'Jonathan Swift'} => true}