创建对象之动态原型模式

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
		//创建对象之动态原型模式
		function Person(name , age , job){
			this.name = name;
			this.age = age;
			this.job = job;
			//判断是否存在
			if( typeof this.sayName != 'function'){
				Person.prototype.sayName = function(){
					console.log(this.name);
				}
			}
		}
		
		var person1 = new Person("宝清老家" , 29 , "Software");
		person1.sayName();
		
		</script>
	</body>
</html>

  

posted on 2016-04-24 16:31  宝清老窖  阅读(142)  评论(0编辑  收藏  举报