this.isDestroy=function () {//销毁条件 飞出界面后销毁 if(bulletY<-height){ return true; } else{ return false; } }; var bulletId; this.isimgDestroy=function () {//销毁条件 飞出界面后销毁 if(this.isDestroy()){ bulletId=document.getElementById('bullet'); bulletId.outerHTML=''; } };
不同的js函数中
this.run=function () { bullets.forEach(function (bullet) { bullet.run(); if(bullet.isDestroy()){ //销毁子弹数组里面的子弹 bullets.splice(bullet,1); //把子弹里面的图片元素销毁 bullet.isimgDestroy(); } }) };