<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title></title>

<script type="text/javascript">
//构造器(有参构造器)
function Student(name, age) {
this.name = name;
this.age = age;
//如果有属性,不希望通过构造器给值
this.grade = "";

this.study = function() {
document.write(this.name + "才" + this.age + "岁,就那么的爱学习");
}

this.eat = function() {
document.write(this.name + "今年" + this.grade);
}
}
</script>
</head>
<!--
描述:类 (推荐)
-->

<body>
<script type="application/javascript">
var student1 = new Student("小周同学", 18);
var student2 = new Student("隔壁老王", 58);

student1.study();
student1.grade = "大四";
student1.eat();

student2.study();
</script>
</body>

</html>