Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 14
    Excellent technique here at tackling the original problem. Deserves an upvote. Commented Dec 9, 2014 at 21:04
  • 4
    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).
    – DDS
    Commented Feb 1, 2015 at 19:51
  • 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.
    – Pylipala
    Commented Jun 3, 2015 at 2:54
  • @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
    – iman
    Commented Jun 4, 2015 at 8:09
  • @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.
    – Pylipala
    Commented Jun 4, 2015 at 8:54