<html>
<head> </head> <body> <script type="text/javascript"> /* function Person(name,age,study){ this.myname = name ; this.myage = age ; this.mystudy = study ; } var p1 = new Person("lwj",21,"qianduan"); //alert(p1.myname); //alert(p1.myage); //alert(p1.mystudy); p1.sex = "男"; //alert(p1.sex); Person.dizhi = "珠海斗门" Person.xuexiao = "南方IT" //alert(Person.dizhi); //alert(Person.xuexiao); function Teacher(name,zhuanye){ this.name = name ; this.zhuanye = zhuanye ; } function Student(name,age,aihao){ this.stuname = name ; this.stuage = age ; this.myaihao = aihao ; this.teacher = new Teacher("cj","js"); } var stu = new Student("lwj",21,["跳舞","听音乐"]); //alert(stu.stuname); //alert(stu.stuage); //alert(stu.myaihao); //stu.teacher = "cj"; //Student.teacher = {}; //Student.teacher.zhuanye = "前端"; //alert(stu.teacher); //alert(Student.teacher.zhuanye); alert("学生姓名:"+stu.stuname+",年龄"+stu.stuage+",爱好:"+stu.myaihao+",老师:"+stu["teacher"].name+",专业:"+stu["teacher"]["zhuanye"]); //alert(stu.teacher.name); //alert(stu.teacher.zhuanye); */ /* var student = { name:"lwj", age:21, teacher:{ name:"cj", zhuanye:"js" } } //alert(student.name); //alert(student.age); //alert(student.teacher.name); //alert(student.teacher.zhuanye); function Teacher(name,zhuanye){ this.name = name ; this.zhuanye = zhuanye ; } var student2 = { name:"lwj", age:21, teacher:new Teacher("cj","js") } //alert(student.name); //alert(student.age); //alert(student.teacher.name); //alert(student.teacher.zhuanye); function Student(name,age){ this.name = name ; this.age = age ; this.teacher = { name:["cj","wl"], zhuanye:["js","qd"] }; } function Student2(name,age){ this.name = name ; this.age = age ; this.teacher = new Teacher("cj","js"); } var stu = new Student("lwj",21); var stu2 = new Student2("lwj",21); //alert(stu.teacher.name+","+stu.teacher.zhuanye); //alert(stu2.teacher.name+","+stu2.teacher.zhuanye); var tcname = stu.teacher.name; for(var i=0.;i<tcname.length;i++){ alert(stu.teacher.name[i]); } var tczhuanye = stu.teacher.zhuanye; for(var i=0.;i<tczhuanye.length;i++){ alert(stu.teacher.zhuanye[i]); } //任何对象都有一个隐藏函数constructor Function是最大的构造函数 //prototype */ //3.创建一个学生类 ,里面有名字、年龄、性别这3个属性 //创建一个班级类 //有一个名字属性 //有一个add方法,用来往班级里面添加一个学生 //有一个getStudentsByGender(通过性别查询学生) //有一个方法getStudentsByAge() function Student(name,age,sex){ this.name = name ; this.age = age ; this.sex = sex ; } function Banji(name){ this.name = name ; } Banji.prototype.addstu = function(stu){ var student = []; student.push(stu); } var s1 = new Student("zs",18,"男"); var s2 = new Student("ls",19,"女"); var bj = new Banji("3ban"); bj.addstu(s1); bj.addstu(s2); </script> </body></html>