How does [b][b = a,0] swap between a and b?

前端 未结 2 474
栀梦
栀梦 2020-12-18 04:06

As gdoron pointed out,

var a = \"a\";
var b = \"b\";

a = [b][b = a,0];

Will swap a and b, and although it looks

2条回答
  •  悲&欢浪女
    2020-12-18 04:38

    It might help (or hinder) to think of it terms of the semantically equivalent lambda construction (here, parameter c takes the place of element 0):

    a = (function(c) { b = a; return c; })(b);
    

提交回复
热议问题