Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const user = {}
Object.defineProperties(user, {
// Data Property
_name: {
value: 'Akash',
enumerable: false,
configurable: false,
writable: false
},
// Accessor Property
name: {
get: function() {
return `I am ${this._firstName} ${this._lastName}`
},
set: function(value) {
console.log('Setting Name To : %s', value)
this._firstName = value
},
enumerable: false,
configurable: false
}
});
// Example
console.log('name' in user) // true
console.log('_name' in user) // true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.