What a strange syntax?

后端 未结 3 1093
温柔的废话
温柔的废话 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:13

    The expression uses two JavaScript features :

    • short circuit evaluation of boolean operators: in statement context, a && (b); is equivalent to if (a) (b);
    • the comma operator to group assignment expressions: in statement context, a=b,b=c; is equivalent to { a=b; b=c }

    As a result the expression is equivalent to:

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

提交回复
热议问题