JS闭包实现常量

<!doctype html>
<html>
	<script>
	var Class = (function(){
		var list = {
			ABC : 'ABC',
			DEF : 'DEF'
		}
		
		var ctor = function(){};
		
		ctor.getContent = function(value){
			return list[value];
		}
		
		return ctor;
	})();
	
	alert(Class.getContent('ABC'));
	</script>
</html>
 

你可能感兴趣的:(js闭包)