Skema: Non-Enumerable Properties
by kaelzhang
HTML
<script src="https://unpkg.com/skema/umd/jsfiddle.js"></script>
<script src="https://unpkg.com/skema/umd/skema.min.js"></script>
JavaScript
const {shape} = Skema
log('example: enumerable')
const A = shape({
foo: {
type: Number,
enumerable: false
},
bar: Number
})
const a = A.from({
foo: 1,
bar: 1
})
success('a.foo', a.foo)
// 'foo' is not enumerable
success('a', a)
log('example: writable')
const B = shape({
foo: {
type: Number,
writable: false
},
bar: Number
})
const b = B.from({
foo: 1,
bar: 1
})
success('b', b)
throws(() => {
// It is not writable, so it throws
b.foo = 2
})
success('b.foo', b.foo)
// b.bar is writable
b.bar = 3
success('b.bar', b.bar)