disappearedng schreef:
Quote:
Hi everyone
It's me again,
this time I am trying to write a function that copies all the fields
from one object to another and supplementing all these fields with the
value null
>
How do I go about it?
>
var myMammal = {
name : 'Herb the Mammal',
get_name : function() {
return this.name;
},
says : function() {
return this.saying || '' ;
}
};
>
var copyfields = function(fromZ, toZ){
for (var name in fromZ)
toZ[name] = "null";
};
>
Firebug complains about toZ not defined. I understand that this is
because of toZ is undefined from the perspective of each "name" in
fromZ.
>
How do I go about this?
|
Hi,
Maybe show some more code?
And why do you use:
var copyfields = function(fromZ, toZ)
instead of
function copyfields (fromZ, toZ)
?
Are you sure you initialized toZ before calling?
eg: var someZ = new Object();
copyfields (fromZ, someZ);
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare