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>jsobject</title>
	<script type="text/javascript">
	  function Address(address,xno){  //address 类
	      this.address=address||'nanchang road';
		  this.xno=xno||787878;
	     this.toString=function(){
			return "street:"+this.address+"xno"+this.xno;
	        }
	    }
	  function person(name,age,address){
		  this.name=name||'kevin';
		  this.age=age||88;
		  this.address=address||new Address(null,null);
	      this.toString=function(){
	        return ''+this.name+'age'+this.age+'add'+this.address;
	     }
      }
	  var jack=new person('keejun',23);
	  var lucy=new person('lucy',null,null);
	  console.log(jack.toString());
	  console.log(lucy.toString());
	</script>
</head>
<body>
</body>
</html>

你可能感兴趣的:(javascript基础(对象))