Created
August 9, 2015 04:24
-
-
Save fnogatz/3037cf0bebee3e3a3d95 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 context = (function () { | |
| function fire (str) { | |
| console.log(str) | |
| } | |
| function getFire () { | |
| return fire | |
| } | |
| return { | |
| fire: fire, | |
| getFire: getFire | |
| } | |
| })() | |
| var calls = [ | |
| 'fire', | |
| 'getFire()', | |
| '(getFire())', | |
| 'function (str) { getFire()(str) }', | |
| 'function (str) { console.log("Hello", str) }', | |
| 'function (str) { console.log(some(), str) }', | |
| ] | |
| var param = 'World' | |
| // Help needed! | |
| // How do I replace the "with"? | |
| with (context) { | |
| ;(function() { | |
| function some() { | |
| return 'Hello' | |
| } | |
| calls.forEach(function (call) { | |
| eval('('+call+')')(param) | |
| }) | |
| })() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment