@sz-sw/object-x
v2.4.3
Published
Creates a '''class''' like object:
Downloads
11
Readme
@sz-sw/object-x
Creates a '''class''' like object:
const {ObjectX, X} = require("@sz-sw/object-x")
let instance = ObjectX.create()
// Adding properties to instance:
X(instance).addProperty.writable.deletable("name", "Bob")
X(instance).addProperty("age", 30)
console.log(instance.name) // Bob
console.log(instance.age) // 30
console.log(instance.nonexisting) // Ooops! Will throw error
delete instance.name
instance.age = 31 // Ooops! Will throw error
Available property modifiers are: enumerable
, writable
and deletable
.
X(instance).seal()
will prevent addition of new properties to instance
.
X(instance).unwrap()
will return instance
.