1

This question is a bit pedantic. You've been warned beforehand :)

I noticed something and I thought of sharing it with you. Let's get straight to it.

Since all functions are supposed to have a prototype property that's epicenter of the prototypical inheritance model in js, and since Function.prototype is a function in itself, you'd expect to see a prototype property on the prototype object that all functions in js get their methods and properties from by virtue of inheritance but nothing there.

Is there a logical explanation behind this decision to omit the prototype on that particular function or it was dropped just for stylistic reasons since Function.prototype.prototype might look ugly for some, or maybe the prototype prop on the Function constructor is like for the lack of a better term the god of all prototypes in js and thus can't have a prototype property itself?

Looking forward to your answers.

Happy coding :)

Mr. X
  • 264
  • 3
  • 6

2 Answers2

1

Even if your browser reports "function", prototypes are objects, or null.

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • 1
    See also http://stackoverflow.com/questions/4859308/in-javascript-why-typeof-function-prototype-is-function-not-object-like-ot?rq=1 – Barmar Feb 27 '15 at 18:28
  • Should I then close this a exact duplicate? – Buhake Sindi Feb 27 '15 at 18:46
  • `Function.prototype` is a special case of the "all prototypes are objects" statement but I am not even asking about this here. I'm asking specifically about `Function.prototype.prototype`. @BuhakeSindi I plead to you that you leave this question open for other people to chime in and provide their input. – Mr. X Feb 27 '15 at 18:57
  • not all that much really. Object don't need to have prototypes, so the fact that Function.prototype does not itself have a prototype is hardly surprising in any way. The only surprise is when you think that the `typeof` evaluation of `Function.prototype` tells us what it truly is. Barmar's link is an excellent follow up on the spec section I reference. – Mike 'Pomax' Kamermans Feb 27 '15 at 22:03
  • @Mike'Pomax'Kamermans Propably `Array.isArray(Array.prototype) //true` is not an array either ... – Mr. X Feb 28 '15 at 11:34
  • correct. it's an object definition that is *used* by the `isArray` function to determine whether something's an array, so it's not an array, and `isArray` will say it is. – Mike 'Pomax' Kamermans Feb 28 '15 at 17:36
  • and probably the addition of `Function.prototype.call`, `Function.prototype.apply`, `Function.prototype.bind` is just a sinister plot by extraterrestrials to mislead us humans to believe that `Function.prototype` is a function when it's a 100% pure object. @Mike'Pomax'Kamermans – Mr. X Feb 28 '15 at 20:07
  • ... what is wrong with you. The function prototype **is** the object that houses the apply, call, etc **Function prototype functions**, of course you can call those. Read the spec linked in this answer and the one given by Barmar. In fact, read the entire spec, it's kind of a cool read with lots of insight on why ES5 does what it does. – Mike 'Pomax' Kamermans Mar 01 '15 at 17:31
  • Again: yes. You're not saying anything new, or contradictory to the answers given so far. At this point I can only assume you've refused to read http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.3.1 and http://www.ecma-international.org/ecma-262/5.1/#sec-15.3.4 and are just making things up for the sake of arguing, so let's cut that short: The answer to your original question has been supplied, with links to the most authoritative resource possible: ECMA-262. Please read that, and move on. – Mike 'Pomax' Kamermans Mar 03 '15 at 22:31
0

"all functions are supposed to have a prototype property"

That has never been true, and is even less true in ES6:

Array.prototype.slice.hasOwnProperty('prototype')  // false
let f = () => {}
f.hasOwnProperty('prototype')  // false
let o = { m() {} }
o.m.hasOwnProperty('prototype')  // false
class C { m() {} }
(new C).m.hasOwnProperty('prototype')  // false

JavaScript distinguishes between functions, and functions that are constructors.

Andreas Rossberg
  • 34,518
  • 3
  • 61
  • 72
  • Please distinguish between an **OWN** property and an _inherited_ property fetched from the prototype chain of every function. The `hasOwnProperty` method only checks for own props nothing more and nothing less. – Mr. X Feb 27 '15 at 18:53