JavaScript
ECMAScript

ECMAScript Classes の継承関係の確認

More than 1 year has passed since last update.
const assert = require('assert');

class Super {}
class Sub extends Super {}
class SubSub extends Sub {}

assert.strictEqual(Sub.prototype instanceof Super, true);
assert.strictEqual(SubSub.prototype instanceof Super, true);

assert.strictEqual(Super.prototype instanceof Sub, false);
assert.strictEqual(SubSub.prototype instanceof Sub, true);

assert.strictEqual(Super.prototype instanceof SubSub, false);
assert.strictEqual(Sub.prototype instanceof SubSub, false);