Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. Function Prototype Property > Last Stop in the prototype Chain is Object.pro...

Last Stop in the prototype Chain is Object.prototype

Since the prototype property is an object, the last stop in the prototype chain or lookup is at Object.prototype. In the code below, I create myArray, which is an empty array. I then attempt to access a property of myArray which has not yet been defined, engaging the prototype lookup chain. The myArray object is examined for the foo property. Being absent, it then looks for the property at Array.prototype, but it is not there, either. So the final place it looks is Object.prototype. Because it is not defined in any of those three objects, the property is undefined.

Live Code

<!DOCTYPE html><html lang="en"><body><script>


var myArray = [];

console.log(myArray.foo) // logs undefined

/* foo was not found at myArray.foo or Array.prototype.foo or  
Object.prototype.foo, so it is undefined. */

</script></body></html>

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint