I have this function :
function fff(){}
Which is a function which is an instance of Function constructor
so fff.__proto__ should show me : function Function() { [native code] }
But it doesn't.
It shows : function Empty() {}
enter image description here
It is only at the constructor property of __proto__ that I see function Function() { [native code] }
Question :
What is this function Empty() {} function
and why fff.__proto__ won't show me : function Function() { [native code] } ?
nb
I know that __proto__ is the actual object that is used in the lookup chain to resolve methods, etc. prototype is the object that is used to build __proto__ when you create an object with new.
But again : function fff is a function which is instantiated behind the scenes by newing Function constructor....so ?
1 Answer 1
You're misunderstanding __proto__.
__proto__ returns the prototype value that the object inherits; not its constructor.
All functions (including Function itself) inherit Function.prototype.
Thus, Function.__proto__ === Function.prototype is true.
This object is specified in section 15.3.4 of the spec:
The Function prototype object is itself a Function object (its
[[Class]]is"Function") that, when invoked, accepts any arguments and returns undefined.
See also
15.3.4.2 Function.prototype.toString ( )
An implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.
The
toStringfunction is not generic; it throws a TypeError exception if its this value is not a Function object. Therefore, it cannot be transferred to other kinds of objects for use as a method.
9 Comments
constructor property (which comes from the prototype)MyFunction.prototype is not a function; it's an object that instances of your function will inherit. See es5.github.io/#x15.3.5.2
nbis incorrect.Emptystill inherits fromObject.prototype. It just has an empty block and no named arguments.