Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically get values of variables local to function in javascript?

Given:

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?

like image 340
jemmons Avatar asked Nov 26 '22 22:11

jemmons


1 Answers

Nope, afraid not.

See: javascript locals()?

like image 52
Shog9 Avatar answered Dec 10 '22 18:12

Shog9