dotslash dotslash - 1 year ago 74
Javascript Question

Objects returned from constructor do not have a prototype

I came across this passage in the wonderful book Eloquent JavaScript:

Constructors (in fact, all functions) automatically get a property
named prototype, which by default holds a plain, empty object that
derives from Object.prototype. Every instance created with this
constructor will have this object as its prototype.

So I thought I'll test it.

function Person () {}

person = new Person()

console.log(Person.prototype) // Object {}
console.log(person.prototype) // undefined ???? :O

The first
makes sense, but why does the second one show

Answer Source

Use Object.getPrototypeOf to get the prototype of specified object

function Person() {}
person = new Person();

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download