paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 388 forks source link

Array.prototype.fill negative arg semantics #270

Closed rwaldron closed 10 years ago

rwaldron commented 10 years ago

Actual:

console.log( [1, 2, 3].fill(4, -3, -2) );    // [1, 2, 3]

Expect:

console.log( [1, 2, 3].fill(4, -3, -2) );    // [4, 2, 3]
// length = 3
// 3 + -3 = 0 <-- calculated start
// 3 + -2 = 1 <-- calculated end

From spec:

If start is negative, it is treated as length+start where length is the length of the array. If end is negative, it is treated as length+end.

ljharb commented 10 years ago

Thanks, will fix

rwaldron commented 10 years ago

That was quick! Thanks :)

ljharb commented 10 years ago

I've got 0.14.0 queued to release but I want to wait on #268