Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Object copying

2 views
Skip to first unread message

Jashin Eugene

unread,
May 31, 2004, 8:51:12 AM5/31/04
to
Hello.
I can't clearly understand what happened in this case:

var a = new Object; //or var a = make_me_obj();, where make_me_obj
creates user defined object from C++.
var b = a;

the var b will have the copy of value a or just another reference to an
object in var a? From what it depends?
and question, is any example (wrote on C++) of class with private data,
which made copy itself in var b in case, described above. More interested in
coding of copy constructors, and order of allocing/deallocing memory for
private data.
Thanks.


Brendan Eich

unread,
Jun 3, 2004, 12:59:41 AM6/3/04
to Jashin Eugene
Jashin Eugene wrote:

> Hello.
> I can't clearly understand what happened in this case:
>
> var a = new Object; //or var a = make_me_obj();, where make_me_obj
> creates user defined object from C++.
> var b = a;
>
> the var b will have the copy of value a or just another reference to an
> object in var a?

Just the reference -- objects are reference types in JS, as in Java.

What is entailed by copying an object depends on the class of the object
and how you use it, so it's up to you to make a copy or clone method.

You need to allocate and set private data in any constructor-like native
function you write, of course. The JSClass.finalize hook should get and
deallocate the private data for the object being finalized.

/be

0 new messages