Very much.
Not all browsers expose the real prototype of an object, so you can't
always navigate the chain. The prototype property of a function/
constructor is exposed, but that only gets you one layer deep.
when you create a function:
var a = function() {};
You also create a prototype object auto-magically:
a.prototype;
This prototype has a magic reference back to the function
a.prototype.constructor === a;
So that's what you're seeing. If you want to navigate the chain on an
object, you need to use the __proto__ property:
var b = new a();
var c = b.__proto__;
var d = c.__proto__;
And so on until Object.prototype, and then finally null
I wouldn't do it in production code though - IE will fail.
On Jun 8, 8:29 pm, Raincole Lai <[email protected]> wrote:
> I read an
> article<http://stackoverflow.com/questions/6276581/prototype-chain-cant-get-o...>which
> explains what prototype chain is.
>
> It says that if I try to access an object's property but it doesn't have it,
> javascript engine will try it's .constructor.propotype. If it doesn't have
> it either then try .construtor.propotype.constructor.propotype. Untill it
> find the built-in Object().
>
> But I test this:
>
> function a() {}
> b = new a();
> c = b.constructor.prototype
>
> I get an empty a object.
>
> d = c.constructor.prototype
>
> I get an empty a object.
>
> It loops. No matter how many .constructor.prototype I call, it can't find
> Object(). What's wrong? Do I misunderstand the prototype chain?
>
> --
> Lai, Yu-Hsuan
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]