a = b; //Where "b" is an object defined by me and contain a private
data pointer.
I notice that the private data pointer in "a" points at the same data
as the pointer in "b". What i really want is to allocate new data and
set the pointer in "a" to point at the new data. Is there some way
control the "copying process" of a self made object?
> When i set an object to equal another object in script:
>
> a = b; //Where "b" is an object defined by me and contain a private
> data pointer.
>
> I notice that the private data pointer in "a" points at the same data
> as the pointer in "b".
Not only that, but a *is* the identical reference to the object
referenced by b. Object is a reference type. There is no copy of the
object, but not of its private data.
> What i really want is to allocate new data and
> set the pointer in "a" to point at the new data. Is there some way
> control the "copying process" of a self made object?
No, you have to provide your own custom method on such objects, or use
an existing method or "copy constructor" if the class is a native one
defined by the JS object (e.g., Date). Which class of objects are you
thinking of, here?
/be
>
Brendan Eich <bre...@meer.net> wrote in message news:<3B9FA719...@meer.net>...
> Daniel wrote:
>
> > When i set an object to equal another object in script:
> >
> > a = b; //Where "b" is an object defined by me and contain a private
> > data pointer.
> >
> > I notice that the private data pointer in "a" points at the same data
> > as the pointer in "b".
>
> Not only that, but a *is* the identical reference to the object
> referenced by b. Object is a reference type. There is no copy of the
> object, but not of its private data.
Now i got a little confused, but I assume that you mean: There IS a
copy of the object, but not of its private data. Otherwise I'm at a
loss.
>
> > What i really want is to allocate new data and
> > set the pointer in "a" to point at the new data. Is there some way
> > control the "copying process" of a self made object?
>
> No, you have to provide your own custom method on such objects, or use
> an existing method or "copy constructor" if the class is a native one
> defined by the JS object (e.g., Date). Which class of objects are you
> thinking of, here?
The class in question is defined by me, and the object is created by
JS_NewObject. To this object I have added a private data pointer. Now,
when the "=" operator is used on the object I want to handle the
copying of the private data differently depending on the class of the
object. What function in the class does the engine call when using the
"=" operator? Or does the engine just copy all the data belonging to
the object (thus copying the pointer and making the "recieving" object
point to the same private data)?
>
> /be
>
> >
/Daniel
First of all I want to thank you for the speedy reply. Thank you.
Brendan Eich <bre...@meer.net> wrote in message news:<3B9FA719...@meer.net>...Daniel wrote:When i set an object to equal another object in script:
a = b; //Where "b" is an object defined by me and contain a private
data pointer.
I notice that the private data pointer in "a" points at the same data
as the pointer in "b".Not only that, but a *is* the identical reference to the object
referenced by b. Object is a reference type. There is no copy of the
object, but not of its private data.
Now i got a little confused, but I assume that you mean: There IS a
copy of the object, but not of its private data. Otherwise I'm at a
loss.
What i really want is to allocate new data and
set the pointer in "a" to point at the new data. Is there some way
control the "copying process" of a self made object?No, you have to provide your own custom method on such objects, or use
an existing method or "copy constructor" if the class is a native one
defined by the JS object (e.g., Date). Which class of objects are you
thinking of, here?
The class in question is defined by me, and the object is created by
JS_NewObject. To this object I have added a private data pointer. Now,
when the "=" operator is used on the object I want to handle the
copying of the private data differently depending on the class of the
object.
What function in the class does the engine call when using the
"=" operator? Or does the engine just copy all the data belonging to
the object (thus copying the pointer and making the "recieving" object
point to the same private data)?
/be
/Daniel
Crystal clear. For some reason I was under the impression that objects
were to be considered as instances of classes, rather than references
to instances of classes, and that the "=" operated in a C++ manner.
Thank you for all the help.
/Daniel
>
> /be
>
> >
> >
> >> /be
> >>
> >
> > /Daniel
>
>
>
>
> --