Just out of curiosity, anything like this possible in JavaScript ?
var c, flag = true;
c = Math.(flag ? min : max)(a, b); // c = flag ? Math.min(a, b) : Math.max(a, b);
You’re almost right. But it won’t work because what are min and max in that context referring to?
You either have to specify a qualified identifier:
(flag ? Math.min : Math.max)(a, b)
Or you use the bracket syntax and just specify the property’s identifier name:
Math[flag ? "min" : "max"](a, b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With