js closure example

A very classic js closure, collect it

<script>

var user = "The window";

var box = {
	user:"The Box",
	getUser:function(){
		var that = this;
		return function(){
			return that.user;
		};
	}
}

//alert(box.getUser()());
//alert(box.getUser().call(box));
alert(box.getUser.call(window)());
</script>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326994965&siteId=291194637