title: How to extend built-in object "Set" to get the last stored value?
body: <p>I want to extend the build-in js object, <strong>Set</strong>, to give it more functionality. I would like to be able to get the value of the item that was stored last. My code snippet does that,</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class MySet extends Set {
    add(value) {
      super.add(value);
      this.last = value;
    }
  }
  
  let a = new MySet([1, 2, 3]);
  a.add(1);
  console.log(a.last); //1</code></pre>
  </div>
  </div>
  </p>
  <p>but there is an issue if I try adding a duplicate value. In the following snippet, the last stored value is 3, and not 1, but with my method I get a 1.</p>
  <p>So I have been wondering how could I extend it so that I would get the actual last stored value.</p>