Does OO JS have a mechanism for casting instance objects to boolean? I would like to be able to use custom instance objects directly in conditionals, and make assertions alo
No, JS does not provide a trap method for casting to boolean. Truthiness of a value is statically determined by the language rules and cannot be changed.
You should give your instances a method to be explicitly invoked like isValid()
, isTruthy()
, isEmpty()
or whatever concept your object represents.