overwrite events after cloning object

overwrite events after cloning object

Hi all,

this i my first post here and i've searched the forums and didn't find any solution for my problem.

I have a JS-Class that contains data and jQuery-DOM-Objects like:
  1. function MyClass
  2. {
  3.       this.property   = 'somevalue';
  4.       this.another    = 'anotherValue';
  5.       this.$head      = $('<div />', {'  
  6.                                     class' : 'niceclass',
  7.                                     click   : $.proxy(this.doSomething, this)
  8.                                };
  9. }
  1. MyClass.prototype.doSomething = function() 
  2. {
  3.       console.log(this);
  4. }
  1. MyClass.prototype.cloneMe = function()
  2. {
  3.       var clone = jQuery.extend(true, {}, this);
  4.       globalarray[index1][index2] = clone;
  5.      
  6.       this.destroy();
  7. }
  1. MyClass.prototype.destroy = function()
  2. {
  3.       globalarray[index1].splice(index2,1);
  4.      
  5.       // little try to built own Destructor to help the Garbage-Collector
  6.       for(var property in this)
  7.       {
  8.             this[property] = null;
  9.       }
  10.       delete this;
  11. }

Instances of my class are stored in an global array, i need to "transfer" them from one index (and dimension) to another, my code seems to work except the event-handlers are pointing (also) to the old object i just destroyed.

TypeError: this.$head is null
this.$head.stop().animate()...
 
How can i fix my problem?

thanks in advance

Ghash















    • Topic Participants

    • info