自定义对象

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>面向对象编程</title>
</head>
<body>
	<script type="text/javascript">
		var cat=new Object();
		cat.name='喵喵';
		cat.age=2;
		cat.color='白色';

		cat.catchMouse=function(){
			console.log(this.name+'抓住一只大老鼠');
		};

		console.log(cat.name,cat.age,cat.color);
		cat.catchMouse();

		var cat1=new Object();
		cat1.name='嗷嗷';
		cat1.age=2;
		cat1.color='花色';

		cat1.catchMouse=function(){
			console.log(this.name+'抓住一只大老鼠');
		}

		console.log(cat1.name,cat1.age,cat1.color);
		cat1.catchMouse();
	</script>

</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44606660/article/details/87856216