函数的封装

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function CreatePerson(name,sex,birthday,fn)
{
this.name =name;
this.sex = sex;
this.birthday = birthday;
}
CreatePerson.prototype.sayHi
= function (name)
{
alert(
"Hi ! I am "+this.name);
alert(name);
}

var person1 = new CreatePerson('zs','boy','2001-02-03');
var person2 = new CreatePerson('ls','boy','2001-02-04');
person1.sayHi(
'111111111111'); //outputs "Hi ! I am zs"
person2.sayHi(); //outputs "Hi ! I am ls"
</script>
</head>
<body>
</body>
</html>
posted on 2011-02-11 18:37  lovening  阅读(205)  评论(0编辑  收藏  举报