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.
Exactly the same stamp can be created in few ways. Here they all are.
const keyPropertyDescriptor = {
key: {
configurable: false,
writable: false,
}
}
const FrozenKey = stampit({
propertyDescriptors: keyPropertyDescriptor
})
const FrozenKey = stampit.propertyDescriptors(keyPropertyDescriptor)
const FrozenKey = stampit().propertyDescriptors(keyPropertyDescriptor)