Blogger Information
Blog 22
fans 3
comment 3
visits 16393
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
构造函数基本用法-2019年7月11号9点01分
辰晨的博客
Original
706 people have browsed it

构造函数

var CreateObj( 参数){

    var this = null;

    this.属性名=属性值;

    this.方法名/函数名 = function(参数){

        var  属性名=属性值;

        var  属性名=属性值;

    }

    return this;

}

运行结果:

3.JPG

<!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>

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:qualified

Teacher's comments:function(name,age,classname,course), funciton 关键字与括号之间必须要有空格
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments