Skip to main content

Timeline for Getting All Variables In Scope

Current License: CC BY-SA 3.0

12 events
when toggle format what by license comment
Jun 15 at 6:07 comment added agiopnl If the answer really is no, why can you then access all defined functions from the window object. What makes variables different than a function..., in the end they're both just objects?
Nov 14, 2019 at 15:20 comment added mathheadinclouds @iman: you don't need eval. Just do everything in the before-run time. See my answer below.
Nov 14, 2019 at 15:18 comment added mathheadinclouds I implemented this, working fiddle available, see my answer below. @Pacerier: there are several, acorn/babel being the strongest/best. You can compare them here: astexplorer.net
Apr 26, 2017 at 15:19 comment added Michael i don't think parsing the code is going to work if the code doesn't explicitly assign the value of the local in a way that you can easily find.. in other words, except for trivial cases it's useless.
Sep 6, 2016 at 21:57 comment added Bryan Grace Such a crafty response. Good find!!
Jun 4, 2015 at 8:54 comment added Pylipala @iman Thanks for your answer. I also guess it is not possible in Javascript side, so I guess if it is possible in v8 side. I found below question link which describe my problem accurately. In it Lasse Reichstein says no but mako-taco says yes. I tried some C++ code as link but do not know how to write it.
Jun 4, 2015 at 8:09 comment added iman @Pylipala The question here is about variables in scope not getting value of a local variables from outside of scope. That's not possible, because this is the definition of local variable that should not be accessible from outside. Regarding your code, you mean context not scope but you didn't put start in the context (this), so you can not read it with this.start. See here: paste.ubuntu.com/11560449
Jun 3, 2015 at 2:54 comment added Pylipala Could you please explain "a simple eval" clear? I tried with below code but could not get variable trapped in scope.function getCounter(start){ return function(){ start ++; return start; } } var counter = getCounter(1); var startInClosure = eval.call(counter, 'this.start;'); console.log(startInClosure); It prints undefined while I expect it should be 2.
Feb 1, 2015 at 19:51 comment added DDS A caller's variables are not necessarily scope variables. Also, scope variables aren't necessarily in the call chain. Variables that have been closed over may be referenced by a closure function upon calling it from a caller that is outside of the definition/closure scope (and whose variables are not at all accessible from withing the closure's body).
Dec 9, 2014 at 21:04 comment added deepelement Excellent technique here at tackling the original problem. Deserves an upvote.
Aug 25, 2014 at 1:42 history edited iman CC BY-SA 3.0
added 279 characters in body
Aug 24, 2014 at 16:01 history answered iman CC BY-SA 3.0