<!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="12233456654";
// student.doHomework=function(){
// console.log(this.name+"正在写作业");
// }
// student.doHomework();
//初始化式
// var student = {
// "name":"Jim",
// mobile: "12233456654",
// 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");
//原型式:不能方便的创建多个对象:实现了自定义方法和构造方法的分离
// function Student(){}
// Student.prototype.name="Jim";
// Student.prototype.mobile="110";
// Student.prototype.doHomework=function(){
// console.log(this.name+"正在做作业");
// }
// var student = new Student();
// 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>