Last active
January 31, 2016 16:38
-
-
Save jthomas/69341518f4a6940e8874 to your computer and use it in GitHub Desktop.
Accessing variables from closure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vm = require('vm'); | |
var Debug = vm.runInDebugContext('Debug'); | |
Debug.setListener(function (event, exec_state) { | |
if (event !== Debug.DebugEvent.Break) return; | |
try { | |
console.log(exec_state.frame(0).evaluate('inner')) | |
} catch (err) { | |
console.log(err) | |
} | |
}); | |
function fails() { | |
var inner = 'inner'; | |
var breakpoint = function () { | |
debugger; | |
} | |
breakpoint(); | |
} | |
function works() { | |
var inner = 'inner'; | |
var breakpoint = function () { | |
var ref = inner; | |
debugger; | |
} | |
breakpoint(); | |
} | |
works(); | |
fails(); |
Author
jthomas
commented
Jan 31, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment