I'm currently building an (ES6) javascript constructor, and was wondering how I should handle "failure". I was thinking about plainly logging to the console and setting this = undefined;, but for some reason that's an "illegal left-hand side assignment". This is roughly what I had in mind:
class Foo {
constructor(foo) {
if (foo === bar) {
// considered "success"
this.foo = foo;
} else {
// failure
console.log("oh noes!");
this = undefined;
}
}
}
Would this be considered a wise practice? I'm just trying to understand what the best practice should be, for failing during the use of a constructor.