0

The following code:

console.log(new function(){return this})

is giving the following output:

output in chrome console

Ref to the img, Please explain the output (why does such infinite repeating depth exists?).

note: I'm a newbie in javascript and was trying various code and found this behavior.

josh3736
  • 139,160
  • 33
  • 216
  • 263
Deepak
  • 1,016
  • 2
  • 9
  • 14

2 Answers2

2

In JavaScript function is object and has all properties which belong to objects. So all of them you see in your console line.

Short description:

name :'' - anonymous function in your case name of function is empty

caller:null function that call your function

arguments: null all arguments which were passed into function

You need take a look at Inheritance of JS

http://phrogz.net/JS/classes/OOPinJS2.html

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Anton Baksheiev
  • 2,211
  • 2
  • 14
  • 15
0
  1. An Object's .constructor property will usually reference a Function,
  2. Functions are objects, which inherit from a prototype object.
  3. The prototype object from which functions inherit has a .constructor property.
  4. Go to step 1
I Hate Lazy
  • 47,415
  • 13
  • 86
  • 77