<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script language="javascript">
function Person(){
Person.cityName="北京";//静态属性
Person.prototype.name="张三";
Person.prototype.age=30;
Person.prototype.sayHello=function(){
alert("Hello!");
}
}
function Student(){
Student.prototype.schoolName="北风网";
//定义私有属性
var gfName = "lingling";
}
function testExt(){
Student.prototype = new Person();//继承的关键!
var stu = new Student();
//alert(stu.name);
//stu.sayHello();
//alert(stu.schoolName);
////alert(stu.gfName);//不可见,因为访问了private的属性
//stu.name="李四";
//alert(stu.name);
var p = new Person();
alert(Person.cityName);
}
</script>
</head>
<body>
<input name="" type="button" value="看结果" onclick="testExt();"/>
</body>
</html>
静态属性,私有属性,对象的继续
最新推荐文章于 2025-08-06 14:36:16 发布