javascript - Using &&'s short-circuiting as an if statement? -
i saw line in jquery.form.js
source code:
g && $.event.trigger("ajaxcomplete", [xhr, s]);
my first thought wtf??
my next thought was, can't decide if that's ugly or elegant.
i'm not javascript guru means question 2-fold. first want confirm understand properly. above line equivalent to:
if (g) { $.event.trigger("ajaxcomplete", [xhr, s]); }
and secondly common / accepted practice in javascript? on 1 hand it's succinct, on other can bit cryptic if haven't seen before.
yes, 2 examples equivalent. works in pretty languages, it's become rather idiomatic in javascript. think it's in situations can abused in others. it's shorter though, can important minimize javascript load times.
also see can explain how john resig's pretty.js javascript works?
Comments
Post a Comment