<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript">
/*
* 创建一个Person构造函数
*/
function Person(name,age,gender){
this.name=name;
this.age=age;
this.gender=gender;
//向对象添加一个方法
this.sayName=fun;
}
//将sayName方法在全局作用域中定义
function fun(){
alert("Hello大家好,我系"+this.name);
};
//创建一个person的实例
var per=new Person("zzz",18,"女");
var per2=new Person("chen",19,"男");
per.sayName();
per2.sayName();
//判断两者是否相等
console.log(per.sayName()==per2.sayName());
</script>
</head>
<body>
</body>
</html>
效果: