The code copy is as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
/*
* Combination mode: constructor mode + prototype mode
This method is the most common way to create objects in javascript
Variable type attribute: passed with constructor
Function type attribute: declared with prototype mode
*/
function Student(name,age){
this.name=name;
this.age=age;
}
Student.prototype.setName=function(name2){
this.name=name2;
};
Student.prototype.getName=function(){
return this.name;
};
var stu1=new Student("Xiao Hu", 21);
alert(stu1.getName());
</script>
</head>
<body>
</body>
</html>