Jeff Stewart wrote:
but the same procedure doesn't work (results in a meaningless
"prototype" key in the 'o' hash) in the usage below?
var o = new Object();
o.prototype = new BaseObject();
Well you could do e.g.
Object.prototype.someProperty = someExpression
and then your o object created with new Object() "inherits" the
someProperty property from the prototype. But manipulating
Object.prototype is rather frowned upon.
In terms of the ECMAScript specification the prototype property/chain of
an individual object is internal and not exposed to user script.
Mozilla's JavaScript engine Spidermonkey however exposes the internal
prototype property to script as a property named __proto__ meaning if
you really think you need to manipulate the prototype chain of
individual objects then in Mozilla you can do e.g.
function Base () {
this.god = 'Kibo';
}
var obj = new Object();
obj.__proto__ = new Base();
alert(obj.god);
and it will alert 'Kibo'.
So there is a prototype for each object or rather a prototype chain,
only ECMAScript does not require that to be exposed to script.
--
Martin Honnen
http://JavaScript.FAQTs.com/