By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,456 Members | 1,742 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,456 IT Pros & Developers. It's quick & easy.

prototype-based vs class-based OOP langauges

P: n/a
I would like to know the benefits for javascripts' prototype objects as
compared to say java class-based objects.
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.

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.

thanks in advance

Neil Morris

--
my IE6 favorites for import into Netscape/Internet Explorer
www.neilmorris.btinternet.co.uk/bookmark.htm
http://www.neilmorris.btinternet.co.uk/
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Neil Morris" <Ne********@btinternet.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/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
> I would like to know the benefits for javascripts' prototype objects as
compared to say java class-based objects.
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.
Yes. See Private Members in JavaScript,
http://www.crockford.com/javascript/private.html
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.


No. However, you don't want to be using deep heirarchies as you did in
static languages. You can get much farther going shallow with
augmentation. See http://www.crockford.com/javascript/inheritance.html
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.