Last active
September 12, 2023 19:18
-
-
Save HasanHuseyinDemir/3e17d805a59f71170c81cb5887be58c5 to your computer and use it in GitHub Desktop.
Proxy Returner
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
function createProxy(obj) { | |
return new Proxy(obj, { | |
get(target, key) { | |
//Callback | |
return target[key]; | |
}, | |
set(target, key, value) { | |
//Callback | |
target[key] = value; | |
return true | |
} | |
}); | |
} | |
/* | |
Example: | |
const values=createProxy({ | |
x:0, | |
y:1, | |
z:2 | |
}) | |
values.x=1 //Callback triggered | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment