Created
July 8, 2014 07:48
-
-
Save DmitryBaranovskiy/b1d843c769fea29c8f49 to your computer and use it in GitHub Desktop.
Anything to anything map using events
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
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