Created
March 26, 2012 13:27
-
-
Save chakrit/2205039 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 unscoped = function(objName) { | |
return eval(objName); | |
}; | |
var x = 111; | |
function newScope() { | |
var x = 222; | |
return unscoped('x'); | |
}; | |
console.log(newScope()); |
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.
How about this ? http://jsbin.com/ekodux/edit#javascript,live
oh, jsbin is a cool site! :) ..
still not working wa huhu.
- chakrit
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
…On Tuesday, March 27, 2012 at 12:01 PM, Phat Wangrungarun wrote:
How about this ? http://jsbin.com/ekodux/edit#javascript,live
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2205039
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 ..