Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created March 26, 2012 13:27
Show Gist options
  • Save chakrit/2205039 to your computer and use it in GitHub Desktop.
Save chakrit/2205039 to your computer and use it in GitHub Desktop.
var unscoped = function(objName) {
return eval(objName);
};
var x = 111;
function newScope() {
var x = 222;
return unscoped('x');
};
console.log(newScope());
@phatograph
Copy link

Still not get want you want to do lol. If just

return unscope(x);

or

return eval(x);

or even

return eval('x');

these seem to be working ..

@chakrit
Copy link
Author

chakrit commented Mar 27, 2012

The thing is that the x variable wouldn't be known in advance, i.e. it could be y or z the unscoped function is only given a simple string, i.e. given a string of variable name in an arbitary scope, what is the best way to obtain reference to that variable? i.e. eval('x = 10') to change it.

@phatograph
Copy link

@chakrit
Copy link
Author

chakrit commented Mar 27, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment