Open varna opened 5 years ago
const distance = new Measure(1, 'km')
const time = new Measure(1, 'h')
const speed = distance / time // new MultiMeasure(distance, time)
const distance = new Measure(1, 'km')
const moreDistance = distance * 10 // new Measure(10, 'km')
const area = distance * distance // new Measure(1, "km2")
This would be cool. Don't know if possible, should do a research on how operators work in JS.
It seems that JavaScript Operator Overloading is impossible.
Workaround with methods:
const distance = new Measure(1, 'km')
const area = distance.multiply(distance) // new Measure(1, "km2")
const distance = new Measure(1, 'km')
const time = new Measure(1, 'h')
const speed = distance.divide(time) // new Measure(1, "km/h")
Idea: type of Measure, that could handle multi dimensional units of different types.