Store values keyed by DOM nodes with set, get, and has
A Node Store in JavaScript works like a Map keyed by DOM nodes. Create a class called NodeStore that allows you to store values associated with DOM nodes. The class should provide the following methods:
Remember, we will be storing DOM nodes, so each retrieval might have the same node item, so we want keys to be unique.
Example:
const node1 = document.createElement('p');
const node2 = document.createElement('p');
const store = new NodeStore();
store.set(node1, 1);
store.set(node2, 2);
console.log(store.get(node1)); // Expected output: 1
console.log(store.get(node2)); // Expected output: 2
This task tests your understanding of JavaScript classes, DOM manipulation, and associative arrays or objects. It’s a practical scenario for frontend developers who need to manage state or metadata associated with specific DOM elements dynamically.