Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

闭包是什么?

$
0
0
//例子1: 
	var x = 1;
	function fn() {
		console.log(x)
	}
	
	//函数fn 形成闭包吗?
	//答案:
	

	//例子2:
	var x = 2;
	funciton fn() {
		return funciton (){
			console.log(x)
		}
	}

	var tempFn = fn()

	//tempFn会形成闭包
	//答案:


	//例子3:
	var x = 3;
	funciton fn() {
		var y = 1;
		return function (){
			console.log(1)
		}
	}

	var tempFn = fn()
	//tempFn形成闭包吗?
	//答案:

	//例子4:
	var x= 4;
	function fn() {
		var y = 1;
		reutrn function () {
			console.log(y)
		}
	}

	var tempFn = fn()
	//tempFn形成闭包吗?
	//答案:

闭包是什么呢?

答案:


Viewing all articles
Browse latest Browse all 14821

Trending Articles