// create a custom constructor Foo function Foo() { } // create an insatnce of Foo var foo = new Foo();
// foo is an instance of Foo alert(foo instanceof Foo);// true // foo is also an instance of Object because // Foo.prototype is an instance of Object. // the interpreter will find the constructor // through the prototype chain. alert(foo instanceof Object);// true
// Prototype chain of the object foo // // __proto__ __proto__ __proto__ // foo -----------> Foo.prototype -----------> Object.prototype -----------> null
// But foo is not an instance of Function, because // we could not find Function.prototype in foo's // prototype chain. alert(foo instanceof Function);// false
// However, its constructor Foo is an instance of // Function. alert(Foo instanceof Function);// true // it's also an instance of Object alert(Foo instanceof Object);// true
// Prototype chain of the constructor Foo // // __proto__ __proto__ __proto__ // Foo -----------> Function.prototype -----------> Object.prototype -----------> null