NumUnit
Last updated
Last updated
NumUnit is a type of Unit that only accepts number
data type as its value. It ensures that at any point of time the value would always be number
.
It doesn't even accept NaN
as it's value.
It implements all the Number.prototype methods available in the environment/browser, including polyfills.
e.g.:toFixed
and toString
, and redirects them to the stored number
value inside the Unit, so when you call Unit.toString()
, it'll be executed on the Unit's value instead of the NumUnit instance itself.
See API reference for more details.
number
NumUnit can not be used as a drop-in replacement for primitive number
value, since NumUnit is a non-primitive data structure, and the actual number
value is stored inside the Unit. See the below comparisons for more clarity.
Default value
0
Value data type
number