Reputation: 155
I am experimenting with the Object.prototype.toString()
method. I understand that created objects are [[Prototype]] linked to the Object.prototype
object, therefore can access this method. However, calling Object.toString()
also works. I'm wondering where the Object constructor can access this method when it doesn't have a direct method .toString()
on itself. Is the Object constructor [[Prototype]] linked to its own prototype object?
Object.toString() // "function Object() { [native code] }"
Upvotes: 1
Views: 67
Reputation: 2313
Object
is a Function
which is an object
.
It's confusing, but because the Object constructor is a function it shares the common Object.prototype methods, and when you run toString
on a function, typically it'll return the function's code.
Upvotes: 2