Skip to content

Instantly share code, notes, and snippets.

@to
Last active March 10, 2018 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save to/f34e95152c3e95c93e7dded99a6d5609 to your computer and use it in GitHub Desktop.
Save to/f34e95152c3e95c93e7dded99a6d5609 to your computer and use it in GitHub Desktop.
'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