JavaScript 갈고리 메커니즘 만 들 기

1556 단어
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>hook</title>
	</head>
	<body>
		<script language="JavaScript" type="text/javascript">
		  //    
		  var load_func_init = function(){
		    alert("load_func_init");
		  }
		  
		  //     JS  ,         
		  var Hook = (function(){
		    //       ,         
		    return {
		      init : function(parameter) {
		        this.callHook(parameter);
		      },
		      callHook : function(parameter) {
		        
		        var s = parameter + "_func";
		        var f = [];
		        
		        for(var h in window) {
		          if (h.indexOf(s) != 0) continue;
		          f.push(h); 
		        }
		        
		        this.actionHook(f);
		      },
	        actionHook : function(array_hook) {
	          
	          var _s,
	              _func,
	              _array = array_hook || [],
	              len = _array.length;
	              
	          if (0 === len) return;
	          
	          for (var i = 0; i < len; i++) {
	            _s = _array[i];
	            _func = window[_s];
	            
	            if (_func === undefined) continue;
	            _func.apply();
	          }
	        }
		    }
		  }());
		  onload = function() {
		    //            (   )
		    Hook.init("load");
		  }
		  //    
		  var load_func_scroll = function() {
		    alert("load_func_scroll");
		  }
		</script>
	</body>
</html>

좋은 웹페이지 즐겨찾기