The constructor + prototype pattern constructs the js custom object of of most commonly
- 2020-03-30 02:54:47
- OfStack
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
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>