Implementing pipes in Javascript using psudo operator overloading
Latest commit 50a64b5 Jun 14, 2013 @danielfewbytes danielfewbytes fixed typo
Failed to load latest commit information. fixed typo Jun 14, 2013
jsPipe.js first commit. Jun 14, 2013

Implementing pipes in Javascript using pseudo operator overloading.

Most of the credit goes to Dr. Axel Rauschmayer that introduced me to the concept of pseudo operator overloading in Javascript in his great article about the subject.

The code it self is pretty simple (containing just 28 lines of Javascript for the actual pipe implementation).

I have used the fact that when doing operations on Objects, the method valueOf of the Object is being triggered. Using a bit of trickery, (and overwriting primitive prototypes) I was able to go as far as to make the following work and produce the expected result:

var result;
| sort
| removeLessThenThree
| doubleAll
| print // prints [8, 12, 18]
| function (value) { result = value; }

This little trick is obviously not suitable for real usage, but it is a great example of Javascript's hidden flexibility.