Jump to content

Kreplock

Members
  • Posts

    6
  • Joined

  • Last visited

Kreplock's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. i hate to be helpless, but i updated my code and get the same behavior (nothing happens on the second click). also, i'm wondering how you would pass arguments using an onclick updated through the DOM? function clicky() { alert("clicky"); aForm.aBn.value = "clicked"; aForm.aBn.onclick = "unClicky";}function unClicky() { alert("unclicky"); aForm.aBn.value = "clicky"; aForm.aBn.onclick = "clicky";}
  2. i was hoping to make button functions dynamic by changing the onclick property on the fly. i'm starting to think JS won't let me. simple example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>A Test Page</title><script language="JavaScript" type="text/javascript"><!--function clicky() { alert("clicky"); aForm.aBn.value = "clicked"; aForm.aBn.onclick = "unClicky()";}function unClicky() { alert("unclicky"); aForm.aBn.value = "clicky"; aForm.aBn.onclick = "clicky()";}//--></script></head><body><form name="aForm"> <input type="button" name="aBn" value="clicky" onclick="clicky()"></form></body></html> can any tell me what's wrong there, or if it's illegal and why?
  3. thanks, that's better than what i was using
  4. 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.
  5. yep. when you instantiate an object it gets a chunk of memory on the heap, with a pointer holding the address where that memory starts. something like that, anyway.so i have two different objects (obj1 and obj2) on the heap until i execute: obj2 = obj1instead of reading the values of obj1 and populating obj2 with copies of those values, it looks like it just overwrites obj2's pointer, so that i now have only 1 object, obj1 and obj2 both pointing to it. the second object no longer has a name pointing to it, so it's gone forever.
  6. i have two instances of a custom object, and would like to copy the values of one into the other: obj2 = obj1 i quickly noticed obj2 gets populated with the address of obj1, not the values. so when i reinitialise obj1 i lose my precious values in obj2 as well.how do i copy the values instead of the location?
×
×
  • Create New...