5

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 ?

asked Oct 28, 2013 at 16:56
8
  • 1
    @duri new && age<18... Commented Oct 28, 2013 at 16:59
  • 1
    Your nb is incorrect. Commented Oct 28, 2013 at 17:03
  • @SLaks stackoverflow.com/a/9959753/859154 Commented Oct 28, 2013 at 17:04
  • the Empty function is for display purposes within the console in chrome Commented Oct 28, 2013 at 17:06
  • 1
    @ArunKillu Empty still inherits from Object.prototype. It just has an empty block and no named arguments. Commented Oct 28, 2013 at 17:09

1 Answer 1

5

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 toString function 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.

answered Oct 28, 2013 at 17:02
Sign up to request clarification or add additional context in comments.

9 Comments

proto is the ctor's prototype--- that helped a lot. thanks slaks. ( i was sure that it is the constructor)
@RoyiNamir: No; that's the constructor property (which comes from the prototype)
I guess the NO part is for my second cpart of the comment
- So can you please tell me - why in this code I dont see the alert while in this one - i do see the alert ? if I create an instance from newing a function - it should go to the Function.prototype....no ?
@RoyiNamir: No. 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
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.