自己动手-Javascript面向对象-继承

 function Person(){
	this.name="haha";
	this.sext="boy";
	this.getName=function(){
		alert(this.name);
	}
	this.sayHello=function(){
		alert("Person hi");
	};
};
function Student(){

};

Student.prototype=new Person();

Student.prototype.sayHello=function(){
	alert("Student hi");
};

var student1=new Student();
var student2=new Student();

student1.sayHello();
student2.sayHello();

alert("student1的sayHello的方法被修改");

student1.sayHello=function(){
	alert("我是student1 hi");
}

student1.sayHello();
student2.sayHello();

 

-------------------------------(华丽分割线)-----------------------------------------------------------------

 

 

function Person(){
	this.name="haha";
	this.sext="boy";
	this.getName=function(){
		alert(this.name);
	}
	this.classroom="Person classroom"
};
function Student(){
};

Student.prototype=new Person();

Student.prototype.classroom="Student room";

var student1=new Student();
var student2=new Student();

alert("student1-classroom-->"+student1.classroom);
alert("student2-classroom-->"+student2.classroom);

alert("开始修改");
student1.classroom="这是student1 room";

alert("student1-classroom-->"+student1.classroom);
alert("student2-classroom-->"+student2.classroom);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值