简体   繁体   English

这个闭包中的外函数变量和外函数是什么?

[英]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.

相关问题 函数关闭显示外部函数的变量 - function closure show up variable of outer function 为什么这不是允许内部函数访问外部函数变量的闭包? - Why is this not a closure that allows an inner function to access an outer function variable? 外部函数的变量不可修改 - Variable in outer function not modifiable 停止从外部闭包执行函数? - Stop function execution from outer closure? 从javascript的闭包内部调用外部函数 - Calling a outer function from within a closure in javascript javascript这个封闭的外部函数有一个绑定'this' - javascript this of the outer function of closure having a bound 'this' 箭头函数不适用于外部变量 - Arrow Function not Working with outer variable 何时闭包在javascript中捕获变量值(在外部函数中定义):何时定义或执行嵌套函数? - When does the closure capture the variable value (defined in an outer function) in javascript: when nested function is defined or executed? JS:进行闭包时,如果我不存储为变量,内部函数如何访问外部函数参数? - JS: When making a closure, how does the inner function access the outer function argument if I'm not storing as a variable? JSDoc:如何声明一个闭包变量(可从外部作用域的嵌套函数中获得)? - JSDoc: how to declare a closure variable (available in a nested function from outer scope)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM