Last active
March 10, 2018 16:52
-
-
Save to/f34e95152c3e95c93e7dded99a6d5609 to your computer and use it in GitHub Desktop.
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
'use strict'; | |
var context = {a : 1, b : 2}; | |
withContext(context, () => { | |
console.log(a); // 1 | |
}); | |
function withContext(context, func){ | |
eval( | |
'let ' + Object.entries(context).map((e => e.join('='))).join(',') + | |
`;(${func})();`); | |
} | |
/* | |
let a=1,b=2;(() => { | |
console.log(a); // 1 | |
})(); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment