myShape=new MySquare(5)
inside MySquare constructor:
theArray.push(this)
the destroy() function:
theArray.removeObj(this)//loops through array then slice “this” (MySquare) out.
my dilemma:
//somewhere else in my main code:
myShape=new MySquare(10) // initialized a second time, got rid of the first new MySquare(5)
except that it didn’t call destroy, so it can’t be removed from the array. I tried to pass a removeObj(this) in the constructor of MySquare but of course, the new MySquare isn’t the same as the old MySquare so theArray returns that it can’t find the thing I’m looking for.
My question is, is there a way to kill the old reference when I use new()? (Beside calling destroy() each time before I re-assign a new value to myShape, which is kind of cumbersome)
Thanks.