4 ms·
From the github page: > Javascript has this one peculiarity called valueOf() this function is designed for primitive handling (numbers and strings) when handlin
by iraldir 7y ago
From the github page:
> Javascript has this one peculiarity called valueOf() this function is designed for primitive handling (numbers and strings) when handling arithmetic operations. Every class can overwrite this function to give it special behavior. This Vector class calls the assigned statement three times for x, y and z. Comparable to trigger arithmetic operation manually for every axis.
Internally the valueOf() implementation returns x in first call, y in second call and z in last call, these results are put into an new Vector object and can be reused further.
That's actually quite clever. Thought it was going to be some sort of eval or build time magic. Not bad.