定义一个Shape构造器
function Shape(x, y, velX, velY, exists) {
this.x = x;
this.y = y;
this.velX = velX;
this.velY = velY;
}
一个新的构造器,要拥有Shape一样的x,y等,并拥有自己的属性color和size
function Ball(x, y, velX, velY, color, size, exists) {
Shape.call(this, x, y, velX, velY, exists)
this.color = color;
this.size = size;
}
定义方法
Ball.prototype.draw = function () {
//方法内容
};
创建实例对象并调用方法
ball=new Ball(10,10,10,10,'#fff',20,false)
ball.draw()