.__proto__ vs. .prototype

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

.__proto__ vs. .prototype

Brian Dupras
What's the difference between the .__proto__ and .prototype syntaxes?

Brian

_______________________________________________
mozilla-jseng mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-jseng
Reply | Threaded
Open this post in threaded view
|

Re: .__proto__ vs. .prototype

Martin Honnen-3


Brian Dupras wrote:

> What's the difference between the .__proto__ and .prototype syntaxes?

With Spidermonkey objects have a property named "__proto__" to access
the prototype chain (well the direct prototype object which then again
has a __proto__ property so you can walk the prototype chain that way),
what you access there is what ECMAScript edition 3 defines as the
internal [[Prototype]] property of objects.
So that __proto__ property is a property Spidermonkey has choosen to
expose to script although the ECMAScript edition does not require that,
there it is required to be implemented internally for property lookup.

Function objects have a property named "prototype" which allows the
function to be used as a constructor. That is defined in ECMAScript
edition 3 and is something any implementation has to provide. Any object
constructed with that function will have that prototype as its internal
prototype respectively in Spidermonkey as its __proto__ property.

Example:

function God (name) {
   this.name = name;
};
God.prototype.praise = function () {
   return "All hail " + this.name;
};

var GOD = new God('Kibo');

GOD.__proto__ === God.prototype

The last expression, the comparsion yields true.



--

        Martin Honnen
        http://JavaScript.FAQTs.com/
_______________________________________________
mozilla-jseng mailing list
[hidden email]
http://mail.mozilla.org/listinfo/mozilla-jseng