If the prototype of `Object` in JavaScript is null, why can I do Object.toString()? -
all newly created objects (with exception of objects created using object.create(null)) contain object object.prototype
in prototype chain. these newly created objects can call newobject.tostring()
because tostring
defined on object.prototype
.
however, internal prototype of object said null
. if that's case, why heck can this:
object.tostring(); // prints: "function object() { [native code] }"
perhaps i've answered own question. tostring
defined on object
constructor function?
why?!
> var obj = object.create(null); undefined > obj.tostring(); typeerror: undefined not function > object.tostring(); "function object() { [native code] }"
see, obj
created null
prototype, when call .tostring()
on it, error happen.
but object
self function, , prototype function object, has .tostring()
method.
Comments
Post a Comment