What a strange syntax?

后端 未结 3 1091
温柔的废话
温柔的废话 2020-11-30 13:43

I\'ve found unknown for me code construction on JQuery site. After some formatting it looks like:

function (a,c) {
    c==null && (c=a,a=null);
            


        
3条回答
  •  时光取名叫无心
    2020-11-30 14:31

    It's a trick that uses boolean short-circuit evaluation to only do the second half if the first evaluates to true. Perl has this commonly:

     or die
    

    where if the first statement failed, the program ends.

    Read it as

    if (c == null) { c = a; a = null; }
    

提交回复
热议问题