简体   繁体   English

如何在范围外访问JavaScript对象键函数变量

[英]How can I access JavaScript object key function variable outside scope

Example: 例:

let boo = {
    'foo' : function() {
        let bar = 94;
    }
} 

I want to access bar variable outside function scope. 我想在功能范围之外访问bar变量。 Can anyone help me please? 谁能帮我吗?

You can't access it as you have it in your code. 您无法访问它,因为它已包含在代码中。 That's how closures work by design. 这就是闭包设计的工作方式。 If you want to "see inside" the closure, provide some sort of "getter" function. 如果要“查看内部”闭包,请提供某种“获取”功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM