Chrome's Javascript console: what does it output in terms of objects? -
from javascript console in chrome:
> function person(name){this.name=name;} undefined
at point, person.prototype should empty object according javascript specs. let's assign it:
> p=person.prototype > person
note that > person clickable , expands to:
constructor: function person(name){this.name=name;} __proto__: object
but... wasn't meant empty object? stuff? if alert:
alert(p)
you [object object]. why, when type in chrome console, come out > person expands? wasn't meant empty object?
thank you!
no, prototype
has constructor
property points function prototype of. , of course inherits object too, internal __proto__
property.
it defined in ecmascript 5 section 13.2, creating function objects:
(...)
16. let proto result of creating new object constructed expression
new object()
whereobject
the standard built-in constructor name.17. call [[defineownproperty]] internal method of proto arguments
"constructor"
, property descriptor {[[value]]: f, { [[writable]]: true, [[enumerable]]: false, [[configurable]]: true}, , false.18. call [[defineownproperty]] internal method of f arguments
"prototype"
, property descriptor {[[value]]: proto, { [[writable]]: true, [[enumerable]]: false, [[configurable]]: false}, , false.(...)
this means nothing else than:
create new empty object called proto (16). define property constructor
on object , set value f (the function itself) (17). define property prototype
on function f , set value proto.
if alert
object, object converted string. default behaviour convert object [object object]
string, unless "special" tostring
method overridden.
the chrome console lists these properties because meant debugging, need information. [object object]
not informative.
fwiw, empty object looks this:
you can see internal __proto__
property here. empty object always inherits default properties, not have own properties.
Comments
Post a Comment