Created
November 25, 2012 03:03
-
-
Save chrisdickinson/4142241 to your computer and use it in GitHub Desktop.
using `with` and harmony proxies to automatically declare otherwise undefined variables
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
#!/usr/bin/env node --harmony-proxies | |
var Fake = function(name) { | |
this.name = name | |
} | |
var y = {} | |
, x = Proxy.create({ | |
has: function(target, name) { return true } | |
, getPropertyDescriptor: function(name) { | |
try { return eval(name) } catch(e) { | |
var x = new Fake(name) | |
return { value: x, | |
writable: true, | |
enumerable: true, | |
configurable: true } | |
} | |
} | |
}) | |
var d | |
with(x) { | |
d = hello | |
} | |
console.log('got', d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment