Re: A suggestion
"Michael Doubez" <michael.doubez@free.fr> wrote in message
news:f3d92096-4019-41d4-a03e-9a8e1f06ffb2@q18g2000vbk.googlegroups.com...
On 14 jan, 21:13, ?? Tiib <oot...@hot.ee> wrote:
On Jan 14, 12:11 pm, Michael Doubez <michael.dou...@free.fr> wrote:
On 13 jan, 20:28, "Paul" <pchris...@yahoo.co.uk> wrote:
An object is the concept of a data structure which consists of member
data
and member functions. This is as much a fact as the fact that the sky
is
blue.
No it is not, except in vulgarisation magazines. A more precise
definition is "an object is an instance of the data structure and
behaviour defined by the object's class". You cannot make abstraction
of the class concept, otherwise, you don't have the model for the
object's state, methods and interaction; even if the class is not
expressed by the language (in some languages where functions are in
fact data members, like in javascript).
"A class" (like in class-based OO languages) makes no sense in
Javascript.
IIRC, in javascrpit OO works on the pattern
function MyClasse(parameter1, parameter2) {
this.attribute1 = parameter1;
this.attribute2 = parameter2;
this.method = function() {
alert("Attributs: " + this.attribute1 + ", " +
this.attribute2);
}
}
var obj = new MyClasse("value1", "value2");
obj.method();
The class does exists although, like in mainy dynamic typing language,
it is not formalized at the language level.
..................................................................
I see where you are coming from in associating this with a C++ class but
this is not the case in Javascript.
In Javascript all objects are created from a simple built-in Object.
...............................................................
When working on the DOM of a page, you still have to lookup the
members and the methods available at the nodes (in fact you do look up
the type of the node); that is the class.
.................................................................
IIRC a DOM node, or node type, is defined in an XML namespace. This is not a
good example to describe the mechanics of JS objects.
.................................................................
Class is other (less flexible) concept than that language
supports. Javascript's prototypes are not classes. Objects have full
freedom to change their data model and behavior during their lifetime
(and may do same to other objects that they know of).
In theory, but in practice, if it they change their interface, they
become useless because you don't know what method you can call. I
won't start the dynamic typing vs static typing all over again, my
only point is that this feature is mainly useful at the development
stage, not at runtime (where a static typing language can then achieve
the same).
.......................................................................
Its not uselss to add new properties to an object at runtime.
It is possible to examine a JS object and determine what properties exist,
and this technique is often used in DOM programming.
.......................................................................
The objects of
Javascript are not forced to stay in prototype where they started in
and so they simply have no class.
They don't have to but, as I said, in practice you do.
As an example, in prototype.js you define classes (among other
things).
In fact, I don't see how you can speak about inheritance without class
and inheritance is (arguably) a base concept of OOP.
Actually, in the implementation, you can work with objects (like in
smalltalk where you can change base of an object, and I suspect
prototype.js does the same) but IMHO metaobjects are just an
implementation of classes.
--
Michael
.....................................................................
I don't know what this file 'prototype.js' is, AFAIK a JS prototpye object
is built into the languge and is not available as a JS file.
But in JS all objects are built upon the built-in basic Object type, not
classes.