<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
//直接创建式
// var student = new Object();
// student.name="jim";
// student.mobile="16478852264";
// student.dohomework=function(){
// console.log(this.name+"正在做作业。。。。。。")
// }
// student.dohomework();
//初始化式
// var student ={
// "name":"jim",
// mobile:"16478852264",
// dohomework:function(){
// console.log(this.name+"正在做作业。。。。。。")
// }
// }
// student.dohomework();
//构造方法式:可以方便的创建多个不同的对象、
// function Student(name,mobile){
// this.name=name;
// this.mobile=mobile;
// this.dohomework=function(){
// console.log(this.name+"正在写作业。。。")
// };
// }
// var student=new Student("jim","110");
// student.dohomework();
//原型式 不能方便地创建多个对象;实现了自定义<i></i>
// function Student(){}
// Student.prototype.name="jim";
// Student.prototype.mobile="12346652144";
// Student.prototype.dohomework=function(){
// console.log(this.name+"正在做作业。。。。")
// }
// var student = new Student();
// student.dohomework();
// student=new Student;
// student.name="lucy";
// student.dohomework();
//混合式(构造函数式+原型式)
function Student(name,mobile){
this.name=name;
this.mobile=mobile;
}
Student.prototype.dohomework=function(){
console.log(this.name+"正在做作业。。。。")
}
var student = new Student("lily","120");
student.dohomework();
</script>
</body>
</html>
