A
In my current example, I have an array and want to disable the elements in the array - but only if they have a property type that equals either 'radio' or 'checkbox'. Looping through the array, this works:
#1But it annoys me in this sort of cases that I have to type the variable's name twice. I tried this instead which didn't work:Code:var t = this.inputs[i].type || null; if(t==='checkbox' || t==='radio') { this.inputs[i].disabled=true; }
#2And this which worked in Firefox and Chrome, but not in IE8:Code:t==='checkbox' || 'radio'
#3Surely, there must be an shorter way of doing it than #1 above?Code:t==='checkbox' | 'radio'
===================================================================
B
While I'm at it, I also find the if-else shorthand great:
#4But it annoys me that it is not possible to do this as in a true shorthand for if without else:Code:(value) ? a=1 : a=2;
#5It works with a hack, e.g. like this:Code:(value) ? a=1; // or at least: (value) ? a=1 : ;
#6That's fine although it looks ugly in the code. Can anyone tell me, why this is not possible then:Code:(value) ? a=1 : 0 ;
#7Code:(value==='mystring') ? a=1 : 0 ;



Reply With Quote

Bookmarks