Take a look at this code:
function Foo () {
console.log(this instanceof Foo);
return { name: "nitesh" };
}
foo = new Foo(); //true
console.log(foo instanceof Foo) //false
- Why is
foonot an instance ofFoo? - Why is
thisan instance ofFoo?
In your
Foofunction, you are returning an object. This is whatfoogets set to. That is not aFooobject, it’s just a “normal” object.Try it this way: