Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is - function Empty() - in javascript ? [duplicate]

Tags:

javascript

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 ?

like image 281
Royi Namir Avatar asked Oct 28 '13 16:10

Royi Namir


People also ask

Is Empty function in JavaScript?

The empty statement is a semicolon ( ; ) indicating that no statement will be executed, even if JavaScript syntax requires one. The opposite behavior, where you want multiple statements, but JavaScript only allows a single one, is possible using a block statement, which combines several statements into a single one.

What does an empty function return JavaScript?

If the length of the object is 0, then the array is considered to be empty and the function will return TRUE. Else the array is not empty and the function will return False.

What is () after function in JavaScript?

Show activity on this post. (function () {}) creates an anonymous function. Adding the () to the end calls the function that was just created. In the case of this particular function, the anonymous function returns several properties to the Browser object.

How check if object is empty JavaScript?

Use Object. Object. keys will return an array, which contains the property names of the object. If the length of the array is 0 , then we know that the object is empty.


1 Answers

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.

like image 163
SLaks Avatar answered Sep 22 '22 21:09

SLaks