---
title: "JS闭包实现常量"
author: "topcss"
date: "2011-07-05T17:26:04Z"
tags: []
categories: ["Web前端"]
slug: "js"
draft: false
lastmod: "2011-07-05T17:26:04Z"
id: 1115151
url: "https://topcss.iteye.com/blog/1115151"
---

```
<!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>
```