javascript基础(对象继承与引用)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title></title>
	<script type="text/javascript">
	  function child(id){
	    this.id=id;
	    this.getid=function (){
	      return this.id;
	     }
	  }
		function base(name){
		  this.name=name;
		  this.getname=function(){
			 return this.name;
		    }
		}
	   child.prototype=new base('base');
	   var child1=new child('child');
	   console.log(child1.getid());
	   console.log(child1.getname());
	   ////////////////////////////
		  var xiaoqiang={
                     name:'xiaoqiang',
                     age:23
		  }
		  var daqiang={
                     name:'',
					 age:34,
		             hobby:{
						first:'working',
						second:'book'
		                 }
		  }
		  function getage(){
		    return this.age;
		  }
		  function gethobby(){
		    return this.hobby;
		  }
		  function gethobbyinfo(){
		     for(var index in this.hobby){
				 var info= this.hobby[index];
				 console.log(info);   
		     }
			  return '';
		  }
		 console.log(getage.call(xiaoqiang));
		 console.log(gethobby.call(daqiang));
		 console.log(gethobbyinfo.call(daqiang));
	</script>
</head>
<body>
</body>
</html>

你可能感兴趣的:(javascript基础(对象继承与引用))