StringUnit
StringUnit vs string
string// initialization
let str = 'Hello';
const unit = new StringUnit({initialValue: 'Hello'});
str === unit // false
str === unit.value() // true
unit + ' World' // 'Hello World'
unit + 1 // 'Hello1'
unit.dispatch('6');
parseInt(unit) // 6
typeof str === 'string' // true
typeof unit === 'object' // true
typeof unit.value() === 'string' // true
// value assignment
str = 'bye';
unit.dispatch('bye');
// value access
console.log(str) // logs 'bye'
console.log(unit.value()) // logs 'bye'
// OR
unit.subscribe(value => console.log(value)) // logs 'bye', will log future valuesLast updated
Was this helpful?