Skip to content

Instantly share code, notes, and snippets.

@awilson28
Last active November 5, 2016 03:35
Show Gist options
  • Save awilson28/a75f8ad1d8900ebe85b5 to your computer and use it in GitHub Desktop.
Save awilson28/a75f8ad1d8900ebe85b5 to your computer and use it in GitHub Desktop.
__proto__ (exercise to be completed in your browser's console)
//DO THIS IN YOUR BROWSER'S CONSOLE

function Parent () {}

/* all functions be default get a public, nonenumerable property on them called PROTOTYPE, 
which is an object that possess a constructor key/property that is a reference to the 
function itself, Parent in this case. This object is called the Parent's prototype. Recall 
that nothing distinguishes a function that is used as a constructor from a function 
that isn't: every function receives a prototype object. */

Parent.prototype; // {}

Parent.prototype.constructor; // Parent

var tom = new Parent()

//notice the DOUBLE underscores surrounding 'proto' 
tom.__proto__   // logs Parent {}

/* notice that the object returned by the NEW operator possesses an inaccessible
__proto__ property that is a reference to the Parent constructor function's
prototype object. Each object created from calling new Parent() will end up 
[[Prototype]]-linked to this prototype object. This link is nothing like the copy 
operation that occurs in truly class-based languages like Java. */

tom.__proto__ === Parent.prototype // logs true

(new Parent).__proto__ === Parent.prototype //logs true
(new Parent).prototype  // logs undefined
@relaxedtomato
Copy link

This line returned the Parent Constructor Function

Parent.prototype.constructor; // function Parent(){}

Maybe something to add (or change)

Parent.prototype.constructor === Parent // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment