<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>犀牛书 对象 学习笔记p150</title>
<script language="javascript" type="text/javascript">
function Rectangle(x,y)//自己构造一个对象
{
this.width=x;
this.height=y;
this.area=rectangle_area;//*****//
}
function rectangle_area()//定义一个求矩形面积的方法
{
return this.width*this.height;
}
function testObject()
{
var r=new Rectangle(3,4);
alert(r.area());//调用面积的方法
var obj=new Object();//利用原型对象Object构造一个obj
obj.title='你好!';
alert(obj.title);
obj.people=new Object();//在Obj的基础上在定义一个对象people
obj.people.name='王世清';
alert(obj.people.name);
obj.people2={name:'wsq',age:22};//在Obj的基础上在定义一个对象people2,利用直接量方法
alert(obj.people2.name+obj.people2.age);
delete obj.people2.name; //删除某个对象的属性
alert(obj.people2.name); //name属性删除后此时的name值是Undefined
alert(obj.people2.age);
}
</script>
</head>
<body onload="testObject()">
</body>
</html>
posted on 2007-10-18 18:20
Crying 阅读(240)
评论(0) 编辑 收藏 所属分类:
JavaScript和CSS