inheritance - Idiomatic subclass relation for ES6 -


this question has answer here:

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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -