Created
June 10, 2017 02:12
-
-
Save bayleedev/839057e6985071e4f5142da2d951d09d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 b = 20; | |
| function foo () { | |
| var a = 10; | |
| console.log('hello $a+$b=30'.replace(/\$\w+/g, function (el) { | |
| return eval(el.substr(1)) | |
| })) | |
| } | |
| foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@blainesch
I thought on this quite a bit last night and decided to attempt a different approach..
Use
return debug.fnat the beginning of any function you would like to debug inside.Wherever you use
echoto inspect inside that function should work now because we replace it.This works by using
arguments.callee.callerto get all the code of the function, that the current function was called inside of.This program alters the original functions code and runs the altered version of the function respecting return values.
Some problems I can see are:
$this.somethingfor matching.thisover to the newly executing function.;at end of code lines.arguments.callee.calleris not available so I have written an alternative...