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.

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

but why is that infinite repetition inside the prototype Object?
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.