[英]Can you not use function variables inside another function's associated code?
[英]Can you use parent function variables inside a returned function in javascript?
下面是函数代码:
function TestFunction(number){
return function(e){
return `${number}`;
}
}
当我在 google 的 devtools 命令行上使用它时,它返回:
function(e){
return `${number}`;
}
所以看起来返回的函数不是用我给 TestFunction 的数字创建的,而是像它写的那样采用字符串。 我尝试使用串联而不是插值,但仍然无法正常工作。 我能做什么?
在第二个函数周围确实有一个闭包,所以它会记住num
是什么。
function a(num) { return function b() { return `${num}`; } } const c = a(6); console.log(c());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.