0

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 Super();
sub instanceof Super // false

1 Answer 1

3

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

function Super(){
 this.prop1 = 'value1';   
}

var sub = new Super();
console.log(sub instanceof Super) // true

It would work as intended

Sign up to request clarification or add additional context in comments.

2 Comments

Please be so kind and go into more details with Because its not an instance of that type
@User789 - I did, it's right after the hyphen in that sentence.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.