数组作为函数的返回值进行结构的时候,一些问题。
"use strict" function returnArray() { var [left, right, top, bottom] = [1, 2 ,3 ,4] console.log(left, right, top, bottom) return [ left, right, top, bottom]; } var [ right,left , ee, dd] = returnArray(); console.log(left+"-"+right+"-"+ee+"-"+dd) //此处right=2 var [ right , ee,left, dd] = returnArray(); console.log(left+"-"+right+"-"+ee+"-"+dd) // 此处right=1
输出:
1 2 3 4 2-1-3-4
1 2 3 4 3-1-2-4