javascript对象和构造函数的一些写法。

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

<script>
	//对象
	var renmin = {
		name:'wulei',
		age:30,
		shuohua: function (){
			alert('name' + name + '正在说话' );
		}
	};
	
	renmin.shuohua();
	
	//构造函数
	function reab(na,ag,sh){
		this.na = na;
		this.ag = ag;
		this.sh = sh;
		this.shuoh = function (){
			alert('名字' + this.na + '姓名' + this.ag + '说话' + this.sh);
		}
	}
	
	
	var reab1 = new reab('姓1','30','saaaaa');
	var reab2 = new reab('姓2','30','saaaaa');
	var reab3 = new reab('姓3','30','saaaaa');
	
	console.log(reab1);
	console.log(reab2);
	console.log(reab3);
	
	
	
</script>

	
</body>
</html>

发表评论

邮箱地址不会被公开。