构造函数
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>
运行实例 »
点击 "运行实例" 按钮查看在线实例