jjzjj

javascript - ES6 函数中 while 循环中的解构赋值不会在循环外传播?

我在ES6中(通过node-esml)实现了一个简单的GCD算法,并且(对我而言)在while循环中更新变量值时出现了奇怪的行为。这段代码非常有效:functiongcdWithTemp(x,y){let[r,rdash]=[x,y]while(r!=0){q=Math.floor(rdash/r)temp=rr=rdash-q*rrdash=temp}return(rdash)}console.log(gcdWithTemp(97,34))返回1的预期答案。但是,如果我删除临时变量并改为使用解构赋值来尝试获得相同的结果:functiongcdWithDestructuredAssig