I have two classes:
class Bar extends Foo { // Foo isn't relevant
constructor(value) {
if (!(value instanceof Foo)) throw "InvalidArgumentException: (...)";
super();
this.value = value;
}
}
class Baz extends Bar {
constructor(value) {
super(value);
}
}
The Bar
constructor
checks if value
is an instance of Foo, it throws an error if it isn't. At least, that's what I wanted it to do. If you pass a Bar
or a Baz
as value, the if-statement returns true
as well. The goal is to only let Foo
s through.
I found this answer already but that didn't really answer my question.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…