Reputation: 161
As I understand the .constructor
value is a Function()
for classes.
In short, why constructor attribute is a Function
and whta the rational about it?
Example:
Set.constructor -> Function()
Upvotes: 0
Views: 22
Reputation: 371019
Classes are (very) special kinds of functions; Set
inherits from Function.prototype
.
Function.prototype
has a constructor
property - that's what Set.constructor
refers to. (Set
does not have an own constructor
property - it's only inherited.)
The constructor of Function.prototype
is what you can call to create a Function instance - which, in this special case, is just Function
.
console.log(Set.constructor === Function);
So
Set.constructor('alert(1);')
is equivalent to
Function('alert(1);')
Upvotes: 1