Closed caub closed 6 years ago
From the FAQ:
Can the upper bound, lower bound or the step argument be an arbitrary Expression? Currently the proposal (arbitrarily) restricts them to be an IdentifierReference or DecimalDigits.
Just to clarify
const a=[1,6,5,7,4,1,2,3,2,1,5,8];
const n = a.length/3; a[0:n] // valid (IdentifierReference)
a[0:(a.length/3)] // not valid
const len = a.length; [...0:len:3].map(i => a[i:i+3]) // valid (IdentifierReference)
[...0:a.length:3].map(i => a[i:i+3]) // not valid
Not allowing expression in the range literal form used for creating ranges [...a:b]
would not be convenient at all
https://github.com/tc39/proposal-slice-notation/issues/19#issuecomment-427798886
Would it throw a SyntaxError for dynamic code like: