Closed hax closed 11 months ago
Basically a[^i] work for all array-likes, the only question is what if a is not an Array-like, eg. Number(a.length) is NaN.
a[^i]
a
Number(a.length)
NaN
let x = {0: 0, 1: 1, '-1': -1} x[^1] // ? x[^1] = '^1' // what will happen?
There are at least four choices:
A. let it be.
So x[^1] get undefined and then x become to {..., 'NaN': '^1'}
x[^1]
undefined
x
{..., 'NaN': '^1'}
Accidently introduce a prop named 'NaN' seems not good.
'NaN'
B. treat it as 0
0
Generic methods on Array (such as push, slice) use behavior LengthOfArrayLike
push
slice
So x[^1] get -1, x become to {..., '-1': '^1'}
-1
{..., '-1': '^1'}
C. throw TypeError
D. x[^1] get undefined, x[^1] = ... throw TypeError
x[^1] = ...
Created a more general issue: #5 . So close this.
Basically
a[^i]
work for all array-likes, the only question is what ifa
is not an Array-like, eg.Number(a.length)
isNaN
.There are at least four choices:
A. let it be.
So
x[^1]
getundefined
and thenx
become to{..., 'NaN': '^1'}
Accidently introduce a prop named
'NaN'
seems not good.B. treat it as
0
Generic methods on Array (such as
push
,slice
) use behavior LengthOfArrayLikeSo
x[^1]
get-1
,x
become to{..., '-1': '^1'}
C. throw TypeError
D.
x[^1]
getundefined
,x[^1] = ...
throw TypeError