Blogger Information
Blog 13
fans 0
comment 0
visits 10418
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
​7月10日作业:构造函数来创建对象
执着的博客
Original
660 people have browsed it

1. 写一个构造函数来创建对象
2. 向构造函数的prototype中添加成员,实现数据在实例间共享

实例

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
	<script>
		// var domain='php.cn';
		// function get(value){
		// 	var site='php中文网';
		// 	return site+value;
		// }
		// console.log(get(domain))
		// var obj={};
		// obj.domain='www.php.cn';
		// obj.get=function(value){
		// 	var site='php中文网';
		// 	return site+value
		// }
		// console.log(obj.domain);
		// console.log(obj.get(obj.domain))
		var Createobj= function(){
			this.domain='php.cn';
			this.get=function (value) {
				var site='php中文网';
				return site+value;
				
			};
		};
		var obj2=new Createobj();
		console.log(obj2.domain);
		console.log(obj2.get(obj2.domain));
		Createobj.email='admin@php.cn';
		Createobj.hello=function (){
			return 'js好学吗?';
		}
		Createobj.prototype.email='admin@php.cn';
		Createobj.prototype.hello='JS真难学';
		var obj3= new Createobj();
		console.log(obj3.email);
		console.log(obj3.hello)
	</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