Re: A suggestion
On Jan 16, 12:50 am, Michael Doubez <michael.dou...@free.fr> wrote:
On 14 jan, 21:13, =D6=F6 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 m=
ember data
and member functions. This is as much a fact as the fact that the s=
ky 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.
There is prototype, you clone that prototype with new, not create
instances of class. You can add methods to prototype outside of that
"contructor" like "MyClasse.prototype.otherMethod = function()
{ return 42; }" and from there on the clones have it too.
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.
No there are no classes in prototype based languages like Javascript,
Actionscript or Lua. Static classes are good for compiled languages
and allow simpler optimizations.
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).
I did not want to imply that more flexible is always superior or that C
++ is not flexible enough. However ... like you see, some template
wizardry of C++ is used to achieve more dynamic types like
boost::variant or more dynamic functions like with boost::bind. So
there is a market for more run-time flexibility in C++ community.
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.
I don't think that it is mandatory concept. In Javascript there are
cloning of prototypes and delegation and reflection. Quite powerful
features if to think of it. Usually when someone talks of inheritance
as OOP concept these days then he mentions delegation as alternative.