inheritance - Idiomatic subclass relation for ES6 -
this question has answer here:
- check if constructor inherits in es6 2 answers
under es6, i've got inheritance hierarchy
class {} class b extends {}
i'm looking analogue instanceof
inherited classes, e.g.
const x = b; if (x extensionof a) { console.log("x derives a"); } else { console.log(":("); } // wish log: "x derives a", // `extensionof` syntax error.
i don't know of extensionof
in es6. best x === || x.prototype instanceof a
"equal or subclass-of" relation or x.prototype instanceof a
"subclass-of" relation. missing prettier?
the easiest way be
if (b.prototype instanceof a) ...
you make function if wanted
function extensionof(superclass, subclass) { return subclass.prototype instanceof superclass; } if (extensionof(a, b)) ...
@loganfsmyth mentions solution work
if (a.isprototypeof(b)) ...
Comments
Post a Comment