if i understand your suggestion right it would resemble this:
function dog() { this.name = name;// ...list of properties}dog.prototype.copy = function(obj) { obj.name = this.name;// ...list of assignment statements for each property}var dog1 = new dog();var dog2 = new dog();dog1.name = "fluffy";dog2.name = "rex";document.write(dog1.name); // prints "fluffy"document.write(dog2.name); // prints "rex"dog1.copy(dog2);document.write(dog1.name); // prints "fluffy"document.write(dog2.name); // prints "fluffy"
that works, but it requires what i was trying to avoid in the first place: manually typing out an assignment statement for every property in an object copy method, which needs to be updated every time the object definition gets changed.i cannot believe JavaScript lacks an easy, one-line solution for copying the values of one object into another object of the same type. it's just not possible that someone would create a language that obtuse. but i cannot find an example of the syntax.i noticed arrays behave the same way.array1 = array2;kills array1 and both names now point to the same array. that's fine, but there must be a way to copy by value, keeping each array separate. i tried:array1[] = array2[];array1() = array2();(array1) = (array2);but none are valid.curiously, document.write(array2); behaves the way i'd expect and returns the entire list of elements, though with those pesky commas.