批改状态:合格
老师批语:function(name,age,classname,course), funciton 关键字与括号之间必须要有空格
构造函数
var CreateObj( 参数){
var this = null;
this.属性名=属性值;
this.方法名/函数名 = function(参数){
var 属性名=属性值;
var 属性名=属性值;
}
return this;
}
运行结果:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>构造函数</title>
</head>
<body>
<script>
var CreateStudent = function(name,age,classname,course){
this.name = name;
this.age = age;
this.classname = classname;
this.course = course;
return this;
}
var student = new CreateStudent('小乔',18,20190701,'php');
console.log(student.name);
console.log(student.age);
console.log(student.classname);
console.log(student.course);
CreateStudent.prototype.grade = 99;
console.log(student.grade);
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号