Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the relationship between function and Function in Javascript

Tags:

javascript

as known in javascript, a function defined as

function somefunc(){
 }

is an instance of its constructor Function. But Function itself is a function either which implies the Function is an instance of Function. Is that what they are? Or there is some other relations between them.

like image 904
do. Avatar asked Aug 16 '26 03:08

do.


1 Answers

Yes, that is exactly what they are. Function is an instance of Function, as are all functions, including constructor functions. This is completely expected and defined by the language specification. All functions also inherit from Object, so the following statements are all true:

new Function() instanceof Function
(function () {}) instanceof Function
new Function() instanceof Object
(function () {}) instanceof Object

Functions can be created using function statements, expressions or the Function constructor. See Function constructor vs function statement.

like image 111
Andy E Avatar answered Aug 18 '26 16:08

Andy E



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!