Javascript Closure

 

 

 

<script type="text/javascript">
	var name = "The Window";
	var object = {
		name : "My Object",
		getNameFunc : function(){
			return function(){
				return this.name;
			};
		}
	};

	console.log(object.getNameFunc()());

	name = "The Window";
	var object2 = {
		name : "My Object",
		getNameFunc2 : function(){
			var that=this;
			return function(){
				return that.name;
			};
		}
	};
	console.log(object2.getNameFunc2()());
</script>

  

posted @ 2015-11-04 17:15  小-黑  阅读(119)  评论(0编辑  收藏  举报