Actually this is double redundant/bad:
var e = e || event;
because 1) e
alreay exists in the scope and 2) you might be assigning e
to e
like this.
Better (and perfect and the only right syntax) would be:
e || (e=event);
Stil bad would be:
e = e || event; // at least no var
@DataZombies
You forgot to remove the , 10
. Now the comma operator comes into play and it always uses 10
and never the regex result. Comma operator? Si.
Great post
]]>~~(( thatString.match(/result_count=(d+)/) || [,5] )[1], 10) |
parseInt(( thatString.match(/result_count=(d+)/) || [,5] )[1], 10) |
var conf = obj.conf || { default:'conf' }; |
etc… good times.
]]>function myEventHandler (e) { var e = e || event; // proceed to use e } |
var dummy = {text:""}, bin = (xmlDoc.selectSingleNode("/root/item/BuyItNowPrice") || dummy).text, offer = (xmlDoc.selectSingleNode("/root/item/BestOfferPrice") || dummy).text; |
instead of
var binNode = xmlDoc.selectSingleNode("/root/item/BuyItNowPrice"), bin = binNode ? binNode.text : "", offerNode = xmlDoc.selectSingleNode("/root/item/BestOfferPrice"), offer = offerNode ? offerNode.text : ""; |
Sometimes I’d have result sets where there could be about 5 optional fields, so this simplified things without having to write a separate function. It meant I could separate my logic from the parsing very easily. It was a trick I’d taught myself so I was really proud at the time, it’s one of the things that made me eager to refactor as much as possible 🙂 Of course, if there had been too many, I’d just write a function to handle it and let that function do the extra leg work to keep the code tight.
I do agree, though, that this is one of the sweeter sides to JS.
]]>