title: How to Prevent Inheritance of Specific Method?
body: <p>Say I have two classes, <code>A</code> and <code>B</code>.  <code>B</code> extends <code>A</code> and therefore inherits all of its methods.  I can override them if I want to as well.  My question is whether or not I can prevent <code>B</code> from inheriting a specific method of <code>A</code>.  What I've tried so far looks like this.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// setup
  class A {
    constructor(x) {
      this.x = x;
    }
  
    valueOf() {
      return this.x;
    }
  
    toString() {
      return `{x:${this.x}}`;
    }
  }
  
  class B extends A {
    constructor(x) {
      super(x);
      delete this.valueOf;
    }
  }
  
  delete B.prototype.valueOf;
  
  // example
  const a = new A(42);
  const b = new B(42);
  
  // should work
  console.log(a.valueOf());
  // should throw TypeError, not a function
  console.log(b.valueOf());</code></pre>
  </div>
  </div>
  </p>