They’re known as infix operators, and they’re inbuilt, and act like Function prototypes.
It’s interesting to note that regular JavaScript doesn’t support things like exponentiation through infix operators, and you’re forced to resort to an extension of Math
:
console.log(Math.pow(7, 2));
Although ES6 fixes this:
console.log(7 ** 2);
Although you can’t create your own infix operators, you can extend them:
Function.prototype['∘'] = function(f){
return x => this(f(x))
}
const multiply = a => b => (a * b)
const double = multiply (2)
const doublethreetimes = (double) ['∘'] (double) ['∘'] (double)
console.log(doublethreetimes(3));
Hope this helps! 🙂
3
solved JavaScript Arithmetic Operators…where are they?