A somewhat late addition based on @iUrii answer using Number.prototype
Using the shorthand square bracket notation [], Number operations can be shown as:
Number.prototype["ӕ"] = function(y){ return this + 2 * y; };
Then, the operation requested can be written (fairly condensed) as:
var custom_op_result = (2)["ӕ"](2);
// Expands out to 2 + 2 * 2 = 6;
// console.log( custom_op_result ) Returns 6
Rather long combinations can also be written using complex notation, variables, parentheses, ect... such as (with above):
Number.prototype["Ϡ"] = function(y){ return this / y; };
Number.prototype["փ"] = function(y){ return y ** this; };
var starting_number = 2;
var custom_op_result = ( starting_number["Ϡ"](2) + (2)["փ"]((2)["ӕ"](2)) ) * 2;
// Expands out to ( 2 / 2 + (2 + 2 * 2) ** 2 ) * 2 = 74
// console.log( custom_op_result ) Returns 74
Or... If you want to get really crazy, and possibly confusing you can even assign the operators to variables individually like so:
var ӕ = "ӕ";
var Ϡ = "Ϡ";
var փ = "փ";
var custom_op_result = (2)[ӕ](2)[Ϡ](2)[փ](2);
// Expands out to 2**( (2+2*2) /2 )
// NOTE: Third property actually works backwards to expected
// Would have "expected" 3**2, except it is reversed as 2**3
// console.log( custom_op_result ) Returns 8
Here's the simple version as a clickable example:
<html>
<head>
<!-- Static Info and Links-->
<title>Quick demo of math operators</title>
<!-- Variable -->
<script type="text/javascript">
function main(){
Number.prototype["Ϡ"] = function(y){ return this + 2 * y; };
var Ϡ = "Ϡ";
var result = (2)[Ϡ](2);
var out_string = "Formula is: 2 Ϡ 2<br>";
out_string += "Where: (R,Ϡ), x Ϡ y = x + 2y<br>";
out_string += ("Result is: " + result);
document.getElementById( "output" ).innerHTML = out_string;
console.log( result );
// Formula is: 2 Ϡ 2
// Where: (R,Ϡ), x Ϡ y = x + 2y
// expands out to result = 2 + 2 * 2;
}
</script>
</head>
<body onLoad="main()" onmousedown="" onmouseup="" onmousemove="">
<div id="output">Initial Text That Should Be Replaced</div>
</body>
</html>
This also leads to reeeally weird stuff that might work (need to test as of 8/26/2024) like operator objects with properties, such as ӕ.pp, that applies (x+(pp++)*y) with each application of the operator. (I'm not sure if math even does that... like anywhere)
Anyway, this technically provides very short operator notation, with what may be almost more condensed notation than any actual writer desires (and bonus pinata features!)
I have also made a small javascript library including this feature. It can be found at: https://github.com/conceptualGabrielPutnam/simple_lib_js
A functional example using this library based method can be tried at: https://raw.githack.com/conceptualGabrielPutnam/simple_lib_js/main/StarterHTML.html
Notably, the original author @Ionică Bizău eventually answered their own question with: https://github.com/IonicaBizau/js-custom-operators that is also a rather elegant way to deal with the issue (although it requires esprima and escodegen and code-mirror for viewing)
valueOfwith existing operators, but that's about it in JavaScript.infixl 6 ∘. Second line:x ∘ y = x + 2 * y.<script>block. This technique is used quite widely. Some well-known examples include Google Traceur.