3

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.

do.
  • 621
  • 1
  • 7
  • 18
  • 1
    Have a look at the ECMAScript specification, for example, [13.1 Creating Function Objects](http://ecma262-5.com/ELS5_HTML.htm#Section_13.2), maybe it helps. – Felix Kling Dec 05 '11 at 09:11
  • There is no relationship between the constructor of the JavaScript function and the JavaScript function itself because the constructor of the JavaScript function isn't written in JavaScript. – noob Dec 05 '11 at 09:12

1 Answers1

4

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.

Community
  • 1
  • 1
Andy E
  • 338,112
  • 86
  • 474
  • 445