473,563 Members | 2,767 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prototype-based vs class-based OOP langauges

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
2 2386
"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.'
Jul 20 '05 #2
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
1236
by: Florian Loitsch | last post by:
hi, in section 10.1.8 (Arguments Object) it is stated that the "internal ] property of the arguments object is the orginal Object prototype object, the one that is the *initial* value of Object.prototype". Furthermore the Object.prototype property has attributes . My question now: what does the "initial" refer to? To the untouched...
8
3741
by: Elf M. Sternberg | last post by:
One of the complaints about prototype.js (google for it if you're not familiar with it) is that it's poorly documented. I have this inkling that the key to understanding prototype.js is in the bind function. The problem with Javascript is that the "this" operator is poorly overloaded and it is often hard to understand in the context of...
8
2046
by: Robert | last post by:
Hi, I can use "with" like this: function MyObject(message) { this.message = message; } function _MyObject_speak() {
4
1760
by: lkrubner | last post by:
I'm reading an essay, I think one of Crockford's, and it has this example in it: function Demo() { } Demo.prototype = new Ancestor(); Demo.prototype.foo = function () { } ; Does Ancestor now have a function called foo? What if I have 5 different objects, all descended from Ancestor? Do
21
3822
by: Rob Somers | last post by:
Hey people, I read a good thread on here regarding the reason why we use function prototypes, and it answered most of my questions, but I wanted to double check on a couple of things, as I am writing something up on functions, and I don't like writing about things I am not sure about. Ok, then, here we go: I initially thought that one...
13
2542
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){}, my_meth2: function(){} }); to define new methods on the MyObj prototype object. Object.extend
11
1505
by: shypen42 | last post by:
Hi all, I'm very confused by the relation between "prototype" and that "Prototype.js" library that seems to be used quite a lot (not by knowledgeable people from this group if I understood correctly). For example, when I do this, I use the keyword (?) "prototype": function Example() {
6
1477
by: mmcloughlin | last post by:
I'm learning about objects and am trying to figure out how basic inheritance works. I've got into the habit of explicitly setting the prototype object with an object literal as it seems to make the creation of a class easier to read/understand. Anyway it seems to break the inheritance chain in the following code and I don't know why. ...
5
2226
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
6
1862
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance" using the prototype property. I realize there are no classes in JS, that code therefore lives in objects instead of class definitions, and that...
0
7665
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3643
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.