Property descriptors
const Key = stampit.props({
key: 'my secret key'
})
const auth = Key()
auth.key === 'my secret key'
auth.key = 'ha ha ha'
auth.key === 'ha ha ha' // oops :(
const FrozenKey = stampit.propertyDescriptors(Key, { // composing the two
key: { // this is a standard JavaScript property descriptor
configurable: false,
writable: false,
}
})
const auth = FrozenKey()
auth.key === 'my secret key'
auth.key = 'ha ha ha'
auth.key === 'my secret key' // OK!!! The "key" was not overwritten.Other ways to add property descriptors
Last updated