日期:2014-05-16  浏览次数:20355 次

简单的Javascript 类

JavaScript类代码

var One=function(){
	var a="";
	var b="";
	return {
		set_a : function (c){
			a=c ;
		},
		set_b : function (d){
			b=d ;
		},
		
		get_a : function (){
			return a ;
		},
		get_b : function (){
			return b ;
		}
		
	};
};

?调用示例:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>javascript 类示例</title>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <script type="text/javascript" src="One.js"></script>
  </head>
  <body>
   <script type="text/javascript">
   		var o= One();
   		o.set_a(12);
   		o.set_b(13);
   		alert(o.get_b());
   </script>
  </body>
</html>
?