Why do these 2 implementations behave differently? What exactly sets them apart when it comes to evaluating their prototypes?
Creating an object with the prototype specified:
function Foo() {}
// creates an object with a specified prototype
var bar = Object.create(Foo);
console.log(Object.getPrototypeOf(bar)); // returns: function Foo(){}
console.log(Foo.isPrototypeOf(bar)); // returns: true
Creating an object with the constructor method:
function Foo() {}
// creates an object with the constructor method
var bar = new Foo();
console.log(Object.getPrototypeOf(bar)); // returns: Foo {}
console.log(Foo.isPrototypeOf(bar)); // returns: false
Also, why does the second implementation return both Foo {}
and false
?