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 > The prototype Chain Returns the First Property...

The prototype Chain Returns the First Property Match It Finds in the Chain

Like the scope chain, the prototype chain will use the first value it finds during the chain lookup.

Modifying the last code example, if we added the same value to the Object.prototype and Array.prototype objects, and then attempted to access a value on an array instance, the value returned would be from the Array.prototype object.

Live Code

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

Object.prototype.foo = 'object-foo';
Array.prototype.foo = 'array-foo';
var myArray = [];

console.log(myArray.foo); // logs 'array-foo', was found at Array.prototype.foo

myArray.foo = 'bar';

console.log(myArray.foo) // logs 'bar', was found at Array.foo

</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