Is there a way to define a method on an object
/ class
in JavaScript that acts like toString
just for booleans? Example (es6):
class MyClass {
toBoolean() {
return this.foo === bar;
}
}
so I can do something like this
const myClass = new MyClass();
if (myClass === true) baz();
sounds crazy to me, but I'm gonna ask nonetheless.