As other users have said, modifying size of your array during the loop is a bad idea.
Try:
var circle = new Array();
circle[0]=1;
circle[1]=2;
circle[2]=3;
circle[3]=4;
function deleteCircle(circle, propName) {
while(circle.length!==0){
erase(circle.pop());
}
}
function erase(elem){
delete elem;
}
alert(circle.length);
deleteCircle(circle,null);
alert(circle.length);
LIVE DEMO
EDIT: Sorry didn't notice you changed the code. Updated:
function circle(){};
circle.prototype.erase = function(){
delete this;
}
var circles = [new circle, new circle, new circle];
function deleteCircle(circle, propName) {
while(circle.length!==0){
circle.pop().erase();
}
}
function circle(){}; //or however you define your class
circle.prototype.erase = function(){ //extend the class
delete this;
}
var circles = [new circle, new circle, new circle]; //your array
function deleteCircle(circle, propName) {
while(circle.length!==0){
circle.pop().erase();
}
}
alert(circles.length);
deleteCircle(circles,null);
alert(circles.length);
LIVE DEMO