DEV Community

Operator Overloading in JavaScript, yes you can!

Adam Crockett ๐ŸŒ€ on January 07, 2020

It struck me that it would be nice to have some form of ByteString in JavaScript utilizing TextEncoder but instead of having some fancy newing up a...
Collapse
 
drsensor profile image
เซฎเผผโš†๏ธฟโš†เผฝใค

I wonder if it still work for vector operation ๐Ÿค”

Collapse
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

I thought about it again, I remember the problem with vector 3 or vector 4 sizes, you need to retain all 4 or 3 values and represent them as a type in such a way that the plus can be used, eg string and number, and then re translate them back to vectors again, it sounds like a fun challenge, let me know if you try it

Collapse
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

It has been a long time but I think I have a vector implementation

Collapse
 
drsensor profile image
เซฎเผผโš†๏ธฟโš†เผฝใค • Edited

How do you detect what kind operation it is (e.g +, *) by just listening on valueOf()?

Thread Thread
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

Here we go, the very technical details
2ality.com/2011/12/fake-operator-o...

Thread Thread
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

Details of that are here 2ality.com/2011/12/fake-operator-o...

Collapse
 
delta456 profile image
Swastik Baranwal

You wrote Oporator instead of Operator.

Collapse
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

Dyslexia, so I meant whatever ๐Ÿ˜

Collapse
 
diek profile image
diek

Oporator it's really nice, I will call oporator to all my tests of this kind of weirdo programming. Ty for inspiring me xD

Thread Thread
 
adam_cyclones profile image
Adam Crockett ๐ŸŒ€

You are most welcome ๐Ÿคช

Collapse
 
pyrocto profile image
Mike Stay

You might enjoy this, then:
reperiendi.wordpress.com/2020/08/3...

Collapse
 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ

ooooooh!