Prototype property of functions

46 views Asked by At

When I try to access the Prototype property of functions it gives me the following result:

console.log(Function.prototype); //  () { [native code] }

But when I perform the same operation on other objects like Arrays it shows me the actual prototype of Array where all the methods are linked

console.log(Array.prototype); //  [constructor: ƒ, concat: ƒ, copyWithin: ƒ, fill: ƒ, find: ƒ, …]

What I really want to know is why the Functions behave differently.

1

There are 1 answers

0
CertainPerformance On BEST ANSWER

Logging functions with console.log will log the text of the function. If the function is not written in JavaScript - for example, like here, if the implementation is provided by the environment - it'll give you [native code] instead.

But there's an easy way to log at the properties on the function, at least in Chrome: use console.dir.

console.dir(Function.prototype)
<img src=" https://i.stack.imgur.com/6GEij.png">

which gives you the function properties as expected, at least in both Chrome and FF.

The functionality of this Function.prototype is described here.