I created these objects and their methods.
var Door = function(no = 10) {
this.number = isNaN(no) ? 10 : no;
}
var Room = function(door) {
this.door = door instanceof Door ? door : new Door();
this.name = 'Room';
}
function MyRoom(){
this.name = 'MyRoom';
}
MyRoom.prototype = new Room();
function HerRoom() {
this.name = 'HerRoom';
}
HerRoom.prototype = new Room();
var $myDoor = new Door(10);
var $herDoor = new Door(5);
var $myRoom = new MyRoom($myDoor);
var $herRoom = new HerRoom($herDoor);
console.log($myDoor, $myRoom.door);
// $myDoor.number is 10
// $myRoom.door.number is 10
console.log($herDoor, $herRoom.door);
// $herDoor.number is 5
// $herRoom.door.number is 10
I am wondering what I did wrong that makes $myDoor == $myRoom.door
, BUT, $herDoor != $herRoom.door
. Can anyone please help me to notice where my mistake is?
Update:
Since, I create
var $herDoor = new Door(5);
var $herRoom = new HerRoom($herDoor);
I am expecting that $herRoom.door.number
is equal to $herDoor.number
. Since,
$herDoor instanceof Door // true;