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

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>
?