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:
- function MyClass
- {
- this.property = 'somevalue';
- this.another = 'anotherValue';
- this.$head = $('<div />', {'
- class' : 'niceclass',
- click : $.proxy(this.doSomething, this)
- };
- }
- MyClass.prototype.doSomething = function()
- {
- console.log(this);
- }
- MyClass.prototype.cloneMe = function()
- {
- var clone = jQuery.extend(true, {}, this);
- globalarray[index1][index2] = clone;
-
- this.destroy();
- }
- MyClass.prototype.destroy = function()
- {
- globalarray[index1].splice(index2,1);
-
- // little try to built own Destructor to help the Garbage-Collector
- for(var property in this)
- {
- this[property] = null;
- }
- delete this;
- }
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
How can i fix my problem?
thanks in advance
Ghash