javascript继承原型继承的例子

<html>
	<head></head>
	<body>
		<script type="text/javascript">
			function Person(name){
				this.name=name;
			}
			
			Person.prototype.getName= function(){
				return this.name;
			}
			
			function User( name , passward){
				this.passward= passward;
				this.name=name;
			}
			
			
			/**
			 * 原型继承
			 * 每次调用new User()创建的对象就会自动拥有Person对象的所有方法
			 * */
			User.prototype= new Person();
			
			User.prototype.getPassward= function(){
				return this.passward;
			}
			
			var per= new Person("Amy");
			document.writeln(per.name);
			document.writeln(per.getName());
			
			var use=new User("hello",18);
			document.writeln(use.name);
			document.writeln(use.passward);
			document.writeln(use.getName());
			document.writeln(use.getPassward());
			
			

		</script>
	</body>
</html>

  


==============================================================================

本博客已经废弃,不在维护。新博客地址:http://wenchao.ren


我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员

==============================================================================
原文地址:https://www.cnblogs.com/rollenholt/p/2118524.html