参考文章: https://juejin.im/post/6846687584710557710
新看到的方法:Object.is(val1,val2);
ES6中用来判断两个值是否相同,
感觉可以用来做其他测试(数据指向 => 修正为 记忆体指向位址问题
),以下~
在vue中很多东西都是透过绑定的方式,这样存取也方便
不过像是遇到要重複使用到绑定的数据并改变时,就会出现...这种情况
data() { return { obA: [0, 1, 2, 3, 4, 5], obB: [] }; }, ... this.obB = this.obA; this.obB.push(999); //this.obA 也被改变了~ console.log(this.obA) // [0, 1, 2, 3, 4, 5,999]; console.log(this.obB) //[0, 1, 2, 3, 4, 5,999]; console.log("判断指向结果 = " + Object.is(this.obB, this.obA)) //true;
对比
ES6扩充套件运算子实现阵列的深层拷贝
this.obB = [...this.obA]; this.obB.push(999); //this.obA 这次就不会被改变 console.log(this.obA) // [0, 1, 2, 3, 4, 5]; console.log(this.obB) //[0, 1, 2, 3, 4, 5,999]; console.log("判断指向结果 = " + Object.is(this.obB, this.obA)) //false;
实测Object.is() 好像除了值得比较,也可以做(数据指向 => 修正为 记忆体指向位址
)判断
如果内容有误再提出修正指导~谢谢~