为什么我不使用Child.Prototype=Parent.Prototype而不是Child.Prototype=新的父();用于Javascript继承?
function GameObject(oImg, x, y) { this.x = x; this.y = y; this.img = oImg; this.hit = new Object(); this.hitBox.x = x; this.hitBox.y = y; this.hitBox.width = oImg.width; this.hitBox.height = oImg.height;}Spaceship.prototype = new GameObject();Spaceship.prototype.constructor = Spaceship; function Spaceship(){ console.log("instantiate ship"); GameObject.apply(this, arguments); this.vx = 0; this.vy = 0; this.speed = 3; this.friction = 0.94;}
this.hitBox.width = oImg.width; this.hitBox.height = oImg.height;
Spaceship.prototype = GameObject.prototype;
if(object instanceof GameObject)
相关分类