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>
相關文章
相關標籤/搜索