title: Implementing Node store function in JavaScript
body: <p>I was asked this question on implementing a store in ES5 and ES6.</p>
  
  <p>I've been trying to solve this problem but I got stuck on how do I store the node</p>
  
  <p>Implementing Store Class:</p>
  
  <blockquote>
    <p>Implement a store class with set(Node, value ), get(Node) and
    has(Node) methods, which stores given Nodes with corresponding values.</p>
  </blockquote>
  
  <p>This is what I was able to write (Pseudo-code)</p>
  
  <pre><code>function Store () {
      this.store = [];
  }
  
  Store.prototype.set = function(node, v) {
      // Problem here would be how do I store the node?
  }
  
  Store.prototype.get = function(node) {
      if(this.has(node)) {
          return this.store.find(each =&gt; {
              // Check to see if it's the same node and return.
          })
      }
  }
  
  Store.prototype.has = function(node) {
      return this.store.indexOf(node) &gt; -1;
  }
  </code></pre>
  
  <p><strong><em>NOTE: WE could be storing a HTML DOM in the store. So key would be a "DOM" element NOT a string.</em></strong></p>
  
  <p><strong>Can someone enlighten me with an example? I would imagine this would work like a Map in ES6. How do I store the DOM node in the first place if i were to implement this in ES5?</strong></p>