If a is identical to c, b is identical to c, why a is not identical to b?
var a = [1, 2, 3]
var b = a
var c = a[0...2]
a === c // true
b === c // true
a === b // false
If a, b, c are constants:
let a = [1, 2, 3]
let b = a
let c = a[0...2]
a === c // true
b === c // true
a === b // true
As @onevcat said, it's might be a bug of Playground. And if you change a
to objects of reference type, all the identity tests will be true
.
class K {}
var a = [K(), K(), K()]
var b = a
var c = a[0...2]
a === c // true
b === c // true
a === b // true
it means that a
, b
& c
share the same storage and elements.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments