Javascript OOP basic

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<title>Basic JavaScript OOP</title>
	</head>
	
	<script type='text/javascript'>
		
		// difine the class
		function Customer(name, addr){
			// private fileds
			var _Name = name;
			var _Address = addr ;
			
			// property
			this.Name = _Name;
			this.Address = _Address
			
			// private method
			function toString(){
				return _Name + ", " + _Address;
			}
			
			// public method
			this.ToString = function(){
				return toString();				
			}
		}
		
		// create object
		var cust = new Customer("Tom", "XXX Avenue");
		
		// access property
		alert(cust.Name + "\n" + cust.Address);
		
		// access method
		alert(cust.ToString());	
		
	</script>
	
	<body>
	</body>
</html>

原文地址:https://www.cnblogs.com/yang_sy/p/1781203.html