17. Create a simple store for DOM element

JavaScript TikTok Meta

easy  - accepted / - tried

We have Map in es6, so we could use any data as key, such as DOM element.

const map = new Map()map.set(domNode, somedata)

What if we need to support old JavaScript env like es5, how would you create your own Node Store as above?

You are asked to implement a Node Store, which supports DOM element as key.

class NodeStore {  set(node, value) {  }    get(node) {  }    has(node) {  }}
  1. Map is disabled when judging your code, it is against the goal of practicing.
  2. You can create a simple general Map polyfill. Or since you are asked to support specially for DOM element, what is special about DOM element?
  3. What is the Time / Space cost of your solution?

Always try to find a better approach.