[英]What is the outer function variable and outer function in this closure?
new to Javascript, I am going through closures and just wondering What the outer function variable and outer function is in this closure? Javascript 新手,我正在浏览闭包,只是想知道这个闭包中的外部函数变量和外部函数是什么?
function hello(name, age) { var message = name + ", who is " + age + " years old, says hi!"; return function sayhi() { console.log(message); }; } var sayHelloToJohn = hello("John", 33); sayHelloToJohn();
In your example, the outer function variable is message
and its params name
age
, and the outer function is hello
.在您的示例中,外部函数变量是
message
及其参数name
age
,外部函数是hello
。
It's about their relative with the function sayHi
.这是关于它们与函数
sayHi
的相对关系。 So sayHi
can use its outer function variable, it knows message
and prints it out as you can see.所以
sayHi
可以使用它的外部函数变量,它知道message
并将其打印出来,如您所见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.