Skip to content

Instantly share code, notes, and snippets.

@simaovergalho
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save simaovergalho/9775a0c8fd135da4e746 to your computer and use it in GitHub Desktop.
Save simaovergalho/9775a0c8fd135da4e746 to your computer and use it in GitHub Desktop.
Embed Private Members Into an Object
//reference to: http://code.tutsplus.com/tutorials/javascript-how-to-embed-private-members-into-an-object--cms-24287
var createProperty = function (obj, prop) {
var currentValue = obj[prop];
Object.defineProperty(obj, prop, {
get: function () { return currentValue; },
set: function (value) {
currentValue = value;
},
enumerable: true,
configurable: true
});
}
var entity = {
property: "hello world"
};
createProperty(entity, "property");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment