以编程方式获取javascript函数的局部变量值? [英] Programmatically get values of variables local to function in javascript?

查看:77
本文介绍了以编程方式获取javascript函数的局部变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于:

function foo(){
  var bar = "quux";
  console.log(/*mystery code here*/);
}

我正在寻找插入评论时会产生价值的代码吧。举例来说,这样的东西在全球范围内起作用:

I'm looking for code that when inserted into the comment would yield the value of bar. By way of illustration, something like this works in a global scope:

var foo = "bar";
var bar = "quux";
console.log(window[foo]);

但是,当然,全局定义的变量会附加到窗口对象。函数的局部变量不是。是否有一些类似的方式以编程方式获取本地函数变量?

But, of course, variables defined globally are appended to the window object. Variables local to a function are not. Is there some similar way to programmatically get to local function variables?

推荐答案

不,不要害怕。

这篇关于以编程方式获取javascript函数的局部变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆