instanceof演算子
JavaScriptでの継承関係のチェックはinstanceof
演算子で確認できます。この書き方は、JavaやPHPとよく似ています。
js
constparent = newParent ();constchild = newChild ();console .log (parent instanceofParent );console .log (parent instanceofChild );console .log (child instanceofParent );console .log (child instanceofChild );
js
constparent = newParent ();constchild = newChild ();console .log (parent instanceofParent );console .log (parent instanceofChild );console .log (child instanceofParent );console .log (child instanceofChild );