0

I'm working my way through Douglas Crockford's JavaScript: The Good Parts and I ran into something in Chapter 4, Functions, which I'm not quite grasping.

Near the beginning of the chapter:

Function Objects

Functions in JavaScript are objects. Objects are collections of name/value pairs having a hidden link to a prototype object. Objects produced from object literals are linked to Object.prototype. Function objects are linked to Function.prototype (which is itself linked to Object.prototype).

Now this seemed pretty straightforward until I tried this:

console.log({}.prototype); // => undefined, ???
console.log({key: 'val'}.prototype); // => undefined
console.log(Object.prototype); // => [object Object]
console.log(function(){}.prototype); // => [object Object]
console.log(Function.prototype); // => function Empty() {}
console.log(function(){}.prototype === Function.prototype); // => false
console.log(function(){}.prototype === Object.prototype); // => false

Can somebody interpret this in light of the excerpt? Based on what I read, object literals should have prototypes and they should be linked in some way to Object.prototype. Additionally, shouldn't there be some link between function(){}.prototype and Function.prototype? And what is the link between Function.prototype and Object.prototype?

Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
t.888
  • 3,862
  • 3
  • 25
  • 31
  • 1
    The links are there, but it's not really anything you can access. It happens "behind the scenes" with no exposure (technical word) through the API. There may be some circumstances where it's good to know all this stuff, but for the most part you don't need to. –  Sep 08 '13 at 22:34
  • Thanks for that. I'm trying to get a handle on all this prototype chain stuff and those results were just confusing me. Chapter 5 should shed some light on it, hopefully. – t.888 Sep 08 '13 at 23:40
  • I was wondering the same and doing the same kind of tests. This is also mentioned (where I get confused) in the chapter 3 "Objects" in the Prototype section. "All objects created from object literals are linked to Object.prototype" – asumaran Oct 06 '13 at 00:39
  • possible duplicate of [How does JavaScript .prototype work?](http://stackoverflow.com/questions/572897/how-does-javascript-prototype-work) – Etheryte Feb 20 '15 at 01:52

0 Answers0