@st-lib/private
v1.0.0
Published
Utility for creating private properties and methods.
Downloads
4
Readme
Utility for creating private properties and methods.
import { createProperty, createMethod } from '@st-lib/private'
const [getProperty, setProperty] = createProperty<string>()
const [method, defineMethod] = createMethod<[string], string>()
class Class {
constructor() {
setProperty(this, 'init property value')
defineMethod(this, (value) => value.toUpperCase())
}
publicMethod() {
const value = getProperty(this) // thows ReferenceError if property not defined
const preparedValue = method(this, value) // thows ReferenceError if method not defined
return preparedValue
}
}