I've a code:
a=function(x){alert(x)}
b=function(x){document.write(x)}
c=1;
[c==1?a:b](':p');
but it's not working. Is possible to do what I want?
Yes, just replace the square brackets with parentheses. You are creating an array literal, but you want to isolate an expression:
(c==1?a:b)(':p');
This would also work, but there is no reason to use it:
[c==1?a:b][0](':p');
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