Skip to content

Instantly share code, notes, and snippets.

@DmitryBaranovskiy
Created July 8, 2014 07:48
Show Gist options
  • Save DmitryBaranovskiy/b1d843c769fea29c8f49 to your computer and use it in GitHub Desktop.
Save DmitryBaranovskiy/b1d843c769fea29c8f49 to your computer and use it in GitHub Desktop.
Anything to anything map using events
function assign(key, value) {
eve.on("{}↔︎{}", function (f) {
if (this == key) {
eve.stop();
f(value);
}
});
}
function get(o) {
var res;
eve("{}↔︎{}", o, function (o2) {
res = o2;
});
return res;
}
var a = {},
b = {};
assign(a, b);
assign(b, 1);
assign("key", "value");
console.log(get(a) == b); //true
console.log(get(b) == b); //false
console.log(get(b) == 1); //true
console.log(get("key") == "value"); //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment