I would like to extend the Boolean object with a prototype that inverts the current value. So far I have been doing something like this:
var bool = true; bool = !bool; console.log(bool);
My attempts to expand the Boolean object were not fruitful. This is how far I got:
Boolean.prototype.invert = function() { return !this.valueOf(); } var bool = true; bool = bool.invert(); console.log(bool);
Close, but not close enough. I am looking for a solution on these lines:
var bool = true; bool.invert(); console.log(bool);
Yes, I know, extending an inline object is usually considered bad. Please keep this discussion for another day.
source share