On Nov 13, 12:00*am, disappearedng <disappeare...@gmail.comwrote:
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?
var my_mammal = {
name : 'Herb the Mammal',
get_name : function() { return this.name },
says : function() { return this.saying || '' }
}
function copy_fields(from_z, to_z)
{
for (var name in from_z)
to_z[name] = null
}
var temp = {}
copy_fields( my_mammal, temp )