javascript 패키지 코드 연구

3712 단어 JavaScripthtml
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
	//       
	(function( window, undefined ) {
		//       a
		var a = function(){
			alert("     ");
			obj.constructor("  ", 1);
		}

		//       b
		var b = function(){
			return obj;
		}

		//          
		obj = {
			type:0x01,
			open:function(){
				alert("open" + this.param + "," + this.num);
			},
			close:function(){
				alert("close" + this.param + "," + this.num);
			},
			constructor:function(param, num){
				this.param = param;
				this.num = num;
			}
		};

		window.a=a;
		window.b=b;
	})(window);

	function test(){
		var k = b();
		k.open();
		k.close();
	}
//-->
</SCRIPT>
 </HEAD>
 <BODY>
<INPUT TYPE="button" VALUE="test" ONCLICK="test();">

 </BODY>
 <script language="javascript" type="text/javascript">	
	a();
 </script>
</HTML>

 또 하나의 일반적인 예:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 <script language="javascript" type="text/javascript">	
	function outer(){
		alert("outer");
		var i = 0;
		var inner = function(){
			i++;
			alert(i);
		};
	
		return inner;
	
	}

	var t = outer();
	t();
	t();
	t();
	t();

 </script>
 </HEAD>

 <BODY>
 <INPUT TYPE="button" VALUE="  " ONCLICK="t();">
 </BODY>
</HTML>

 마지막 유사 한 첫 번 째 예:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
 <script language="javascript" type="text/javascript">	
	(function (window){
		alert("outer");
		var i = 0;
		var inner = function(){
			i++;
			alert(i);
		};
		window.inner = inner;
	})(window);

	inner();
	inner();
	inner();

 </script>
 </HEAD>

 <BODY>
 <INPUT TYPE="button" VALUE="  " ONCLICK="inner();">
 </BODY>
</HTML>

좋은 웹페이지 즐겨찾기