Last active
February 19, 2017 18:17
-
-
Save aneelkkhatri/b628b8af3bc26b1afc20730f9dcfd911 to your computer and use it in GitHub Desktop.
Generic property get set adder
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 setupProperty(obj, prop, setcb) { | |
Object.defineProperty(obj, prop, { | |
get: function() { | |
return obj['__'+prop]; | |
}, | |
set: function(v) { | |
console.log(prop); | |
obj['__'+prop] = v; | |
if (setcb) setcb(v); | |
} | |
}); | |
} | |
// Use | |
setupProperty(obj, 'my_prop', function (v) { | |
// ... set sub property of v | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment