title: Extending the Boolean Object in Javascript with an 'invert' function
body: <p>I would like to extend the Boolean object with a prototype function that inverts it's current value. Until now, I've been doing something like this:</p>
  
  <pre><code>var bool = true;
  bool = !bool;
  console.log(bool);  // false
  </code></pre>
  
  <p>My attempts at extending the Boolean object were not fruitful. That's how far I got:</p>
  
  <pre><code>Boolean.prototype.invert = function() {
      return !this.valueOf();
  }
  
  var bool = true;
  bool = bool.invert();
  console.log(bool);  // false
  </code></pre>
  
  <p>Close, but not close enough. I am looking for a solution along these lines:</p>
  
  <pre><code>var bool = true;
  bool.invert();
  console.log(bool);  // false
  </code></pre>
  
  <p><em>Yes, I know, extending build-in Object is commonly considered a bad idea. Please let's save that discussion for another day.</em></p>