function Box(name,age) { this.name=name; this.age=age;}Box.PRototype.run=function () {//写成原型,方便节省内存空间。 return this.name+this.age+'正在运行中!';}function Desk(name,age,passWord) { this.password=password; Box.call(this,name,age);//对象冒充. this.changePW=function () { return this.password; }}Desk.prototype=new Box();//原型继承,实现多个实例化只需分配一次地址,节省内存空间。var desk=new Desk('等等',110,1122);//以下是测试:alert(desk.run());alert(desk.changePW());alert(desk.age);alert(desk.name);alert(desk.password);
新闻热点
疑难解答