1

Why does the following hold:

let F = function () {};
let f = new F();
console.log(f.__proto__.constructor === F, f.constructor === F);
// true

But the following does not:

let F = function () {};
console.log(F.prototype.constructor === F, F.constructor === F);
// true false

What then would be the constructor of a function declaration?

2 Answers 2

2

The .constructor property is an object is what you can call new on to create another such object.

That is, someF.constructor points to F, and you can use new F() to create someOtherF.

So, if F itself is what you want to make a similar type of object - what can you call to construct a function? Function.

let F = function () {};
console.log(F.constructor === Function);

In other words - you could use new Function to create something similar to F - a function that can create instances when new is called on it.

(That said, this would be extremely unusual - 99% of the time, functions should not be dynamic - there's no good reason to use new Function)

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

Comments

0

The constructor of a function is Function.

let F = function () {};
console.log(F.__proto__.constructor === Function, F.constructor === Function);
// true false

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.