<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
//使用原型创建对象
//function Person(){
// Person.prototype.name = "王益凯";
// Person.prototype.age = 18;
// Person.prototype.say = function() {
// alert("我的名字是:"+this.name+",我今年"+this.age+"岁了");
// }
// var p1=new Person();
// p1.say();//正常访问
// say();//报错
//常见的原型检测方式
//alert(Person.prototype.isPrototypePf(p1))
//检测p1的构造器是否指向Person对象
//alert(p1.constructor==Person)
//检测摸个属性是不是自己内存中的
// function Person(name,age){
// this.name=name;
// this.age=age;
// this.say=function(){
// alert("我的名字:"+this.name+",我的年龄:"+this.age);
// }
// }
// var p1=new Person("王益凯",16);
// var p2=new Person("王豆芽",14);
// p1.say();
// p2.say();
// alert(p1 instanceof Person);
// function Person(){}
// Person.prototype.say=function(){
// alert("我是:"+this.name+",我的性别是:"+this.sex+",我今年"+this.age+"岁了。")
//};
// var p1=new Person();
// p1.name="白猫";
// p1.age="1";
// p1.sex="公"
// p1.say();
// var p2=new Person();
// p1.name="白猫";
// p1.age="2";
// p1.sex="母"
// p1.say();
// var p3=new Person();
// p1.name="白猫";
// p1.age="3";
// p1.sex="公"
// p1.say();
// function Person(name,age,friends){
// this.name=name;
// this.age=age;
// this.friends=friends;
// };
// Person.prototype={
// constructor:Person,
// "say":function(){
// alert("我是:"+this.name+",我的:"+this.age+",我今年"+this.friends+"岁了。")
// }
// }
// var p1=new Person("王益凯",22,["老孙","老徐"]);
// p1.friends.push("老刘");
// alert(p1.friends);
// p1.say();
//
//作业:使用json定义一组数据:一个班有5个人,每个人有姓名,年龄,性别,每个人都有一组朋友,每个人都有一个方法say,会说出自己的相关信息.
// var ourClass=[{
// name:"王益凯",age:22,sex:"男",friends:["杨嘉明","王彭彬","耿敢冲","耿标兵"],
// say:function(){
// alert("我的名字是:"+this.name+"。我今年"+this.age+"岁了。我的性别是"+this.sex);
// }
// },
// {
// name:"王彭彬",age:22,sex:"男",friends:["杨嘉明","王益凯","耿敢冲","耿标兵"],
// say:function(){
// alert("我的名字是:"+this.name+"。我今年"+this.age+"岁了。我的性别是"+this.sex);
// }
// },
// {
// name:"杨嘉明",age:22,sex:"男",friends:["王益凯","王彭彬","耿敢冲","耿标兵"],
// say:function(){
// alert("我的名字是:"+this.name+"。我今年"+this.age+"岁了。我的性别是"+this.sex);
// }
// },
// {
// name:"耿敢冲",age:22,sex:"男",friends:["杨嘉明","王彭彬","王益凯","耿标兵"],
// say:function(){
// alert("我的名字是:"+this.name+"。我今年"+this.age+"岁了。我的性别是"+this.sex);
// }
// },
// {
// name:"耿标兵",age:22,sex:"男",friends:["杨嘉明","王彭彬","耿敢冲","王益凯"],
// say:function(){
// alert("我的名字是:"+this.name+"。我今年"+this.age+"岁了。我的性别是"+this.sex);
// }
// }
//
// ]
//
</head>
<body>
</body>
</html>