构造函数实例一

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>面向对象编程</title>
</head>
<body>
	<script type="text/javascript">
		function Cat(name,age,color){
			this.name=name;
			this.age=age;
			this.color=color;
			this.catchMouse=function(){
                console.log(this.name+'抓老鼠');
			};
		}
		var c=new Cat('花花',2,'花色');

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

</body>
</html>

猜你喜欢

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