Skip to content Skip to sidebar Skip to footer

Javascript Instanceof

Can you please tell my why in the example below sub instanceof Super is false? function Super(){ var obj = { prop1: 'value1' }; return obj; } var sub = new Sup

Solution 1:

Because its not an instance of that type - you've returned an anonymous object. If you would have written it like this:

functionSuper(){
 this.prop1 = 'value1';   
}

var sub = newSuper();
console.log(sub instanceofSuper) // true

It would work as intended

Post a Comment for "Javascript Instanceof"