Blogger Information
Blog 35
fans 0
comment 0
visits 32664
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JavaScript创建对象的方式-2018-9-18
THPHP
Original
937 people have browsed it

JavaScript创建对象的方式:

实例

<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
 </head>
 <body>
  <script>
	// 构造方法创建JavaScript对象
	function Stu(naem,sex,age){
		this.name = name;
		this.sex = sex;
		this.age = age;
	}
	let stu = new Stu('小白','男',20);
	console.log(stu);

	// 函数创建对象
	function cer(name,age){
		var obj = new Object();
		obj.name = name;
		obj.age = age;
		return obj;
	}
	let cer1 = cer('天达',22);
	console.log(cer1);

	// 字面量创建对象
	let arr = {name:'天弘',fun:function(){return this.name}}
	console.log(arr.name);
  </script>
 </body>
</html>

运行实例 »

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


Correction status:qualified

Teacher's comments:
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
Author's latest blog post