title: Access JavaScript map similarly to plain object
body: <p>I am using Map</p>
  
  <p>because I want to store an object as a key.</p>
  
  <p>My question is - can I access a map the same way I would access a plain object?</p>
  
  <p>For example:</p>
  
  <pre><code>let m = new Map();
  let obj = {foo:'bar'};
  m[obj] = 'baz';
  console.log(m[obj]);
  </code></pre>
  
  <p>is this supposed to work correctly as is, or do I need to use the get/set methods of a Map?</p>
  
  <p>The reason I ask is because if I need to use get/set it forces to me to carefully refactor a lot of code.</p>
  
  <p>Here is a real life example of code that may need to be refactored:</p>
  
  <p><em>// before (broker.wsLock was plain object)</em></p>
  
  <pre><code>function addWsLockKey(broker, ws, key) {
    let v;
    if (!( v = broker.wsLock[ws])) {
      v = broker.wsLock[ws] = [];
    }
    if (v.indexOf(key) &lt; 0) {
      v.push(key);
    }
  }
  </code></pre>
  
  <p><em>// after (broker.wsLock is a Map instance)</em></p>
  
  <pre><code>function addWsLockKey(broker, ws, key) {
    let v;
    if (!( v = broker.wsLock.get(ws))) {
      v = [];
      broker.wsLock.set(ws, v);
    }
    if (v.indexOf(key) &lt; 0) {
      v.push(key);
    }
  }
  </code></pre>
  
  <p>is there some way to set v on the same line as the set() call?</p>