0

thisis my code part 1

file path is D:\code\test.js,export TestClone

class Test {
  
}

class Test2 extends Test {

}


module.exports.TestClone = Test2

this my code part 2

file path is D:\code\test2.js,export TestClone

const { TestClone } = require('./test');
class Test {
  
}

class Test2 extends Test {

}

console.log(new Test2() instanceof TestClone); // false

The name and structure of the two classes are the same, but why is it false

Ethan Hunt
  • 16
  • 4
  • 3
    because `{} !== {}` - in other words ... Test2 in test2 is not the same object (yes, a class is just an object too) as Test2 in test – Jaromanda X Aug 01 '22 at 04:40
  • Is it because the addresses in memory are different – Ethan Hunt Aug 01 '22 at 05:09
  • Because there is no memory address that can be printed like Java, I want to try to find a convincing evidence to prove it – Ethan Hunt Aug 01 '22 at 05:10
  • no, it's because `Test2` in `test.js` is not the same object as `Test2` in `test2.js` - but, I repeat myself - equality of objects isn't about them "looking the same", it's about them "being the same thing" – Jaromanda X Aug 01 '22 at 05:11
  • I see. It's just that the name confuses the concept. It's actually two different objects. thank you – Ethan Hunt Aug 01 '22 at 05:23

0 Answers0