for (var i = 0; i<num ; i++) {
var obj = new starObj();
stars.push(obj);
stars[i].init();
}
这段代码中的var obj = new starObj();是什么意思?是new 一个对象是吗?
请问他和下面这段代码是什么关系呀?
var starObj = function () {
this.x;
this.y;
}
starObj.prototype.init = function () {
this.x = Math.random()*600 +100;
this.y = Math.random()*300 + 150;
}
starObj.prototype.draw = function () {
cxt.drawImage(starPic,this.x,this.y)
}
function drawStars () {
for (var i = 0; i<num;i++){
stars[i].draw();
}
}