From: John G Harris on
On Sun, 6 Jun 2010 at 03:15:27, in comp.lang.javascript, M A Hossain
Tonu wrote:

<snip>
>And when it comes to inheritance, objects
>inherit from objects, not classes from classes as in the "class"-ical
>languages.
<snip>

That's not true about classical OO languages. In C++ and Java each
derived-type object inherits instance data from the base-type object
inside itself. Functions could be per instance, but there's no point as
it's the same functions for each instance. They are more conveniently
accessed via a shared v-table (which is *not* the "class" whatever the
more mystical bloggers might pretend).

The big difference, and it looks less and less different the more you
look at source code, is that in C++ and Java the objects' data and
functions are defined in a piece of text flagged as a class definition,
and in javascript they are defined in a piece of text flagged as a
constructor definition.

John
--
John Harris
From: Sherelle on
On Jun 6, 4:35 am, M A Hossain Tonu <maht...(a)gmail.com> wrote:
> The problem with that clone method, that if you have sub objects
> within the obj, their references will be cloned, and not the values of
> every sub object.
>
> On Jun 6, 5:20 pm, Lasse Reichstein Nielsen <lrn.unr...(a)gmail.com>
> wrote:
>
> > M A Hossain Tonu <maht...(a)gmail.com> writes:
>
> > >> var clone = function(o) {
> > >>     var no = {};
> > >>     for ( var i in o ) {
> > >>         no[i] = o[i];
> > >>     }
> > >>     return no;
>
> > >> }
>
> > >> var a = {a: 1, b: 2},
> > >>     b = clone(a),
> > >>     c = a;
> > > a.a = 3;
> > > b.a = 4;
> > > console.log(a.a, b.a, c.a);
>
> > > outputs 4 4 4 they are using same memory...
>
> > No, it doesn't. The b variable holds a reference to a different object,
> > and it writes 3,4,3.
>
> > > cause they are copy not an unique instance....so where is the
> > > singelton pattern violated?
>
> > The "singleton pattern" makes no sense in a classless language.
> > It means that you can only create one instance of a specific class.
> > It has no meaning when there are no classes.
> > What would it be that you could only create on instance of?
>
> > /L 'You could do it with host objects, but then, you can do
> >     anything with those'
> > --
> > Lasse Reichstein Holst Nielsen
> >  'Javascript frameworks is a disruptive technology'
>
>

The clone method used was created to illustrate the problem with the
reasoning in the article. Cloning sub-objects is a trivial matter of
recursion.