"Neil Morris" <Ne********@bti nternet.com> writes:
I would like to know the benefits for javascripts' prototype objects as
compared to say java class-based objects.
The advantage is the ease of dynamic modification, something that
isn't possible when your class structure is fixed at compile time.
The main points that I have on my mind are:
1. Is there a way to mark properties in prototype-based langauges as 'final
or 'private' as you can in java so that some properties are 'hidden' from
child objects.
No. When you use an object as prototype, you can see all its properties.
If you want to change it, you can set another property on the child.
2. Is there a way for objects to limit the delete function in javascript, or
any prototype-based langauge, to prevent to object structure from been
'broken'. ie if an object 'a' has a child object 'b', can object 'b' rely on
the fact object 'a' provides the features the next time object 'b' is used.
Don't know about other languages, but not in Javascript.
If you want to depend on a property, make it a property of yourself
("b.prop = b.prop;" will make the property of the prototype a property
of b itself)>
Some build-in properties cannot be deleted, but there is no way to set
that on user defined properties.
I must admit that I don't like the way delete works in Javascript,
because you can indirectly delete a property of the prototype using
only the child. I don't think that should be possible. The prototype
should not be mutable through a child reference, only through a direct
reference.
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'