Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created November 25, 2012 03:03
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 chrisdickinson/4142241 to your computer and use it in GitHub Desktop.
Save chrisdickinson/4142241 to your computer and use it in GitHub Desktop.
using `with` and harmony proxies to automatically declare otherwise undefined variables
#!/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