Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Last active August 29, 2015 13:57
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 heapwolf/9769400 to your computer and use it in GitHub Desktop.
Save heapwolf/9769400 to your computer and use it in GitHub Desktop.
scope chain storage
function get(name) {
var c = arguments.callee.caller
while(c) {
if (c[name]) return c[name]
c = c.arguments.callee.caller
}
}
function set(name, value) {
var p = arguments.callee.caller
p.arguments.callee[name] = value
}
function three() {
console.log(get('x'))
}
function two() {
three()
}
function one() {
set('x', 100)
two()
}
one()
exports.get = function get(name) {
var c = arguments.callee.caller
while(c) {
if (c[name]) return c[name]
c = c.arguments.callee.caller
}
}
exports.set = function set(name, value) {
var p = arguments.callee.caller
p.arguments.callee[name] = value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment