tc39 / proposal-array-last

A JavaScript TC39 Proposal for getting the last element from an array
311 stars 13 forks source link

Polyfill does not use semi-colons #8

Closed JakeChampion closed 6 years ago

JakeChampion commented 6 years ago

I would have expected the polyfill to make use of semi-colons because the TC39 recommend the use of semi-colons.

ljharb commented 6 years ago

That recommendation is not yet merged.

(Separately, polyfills included in proposal repos are not intended for production use, and are solely intended to be explanatory - as such, it’s not really important that the code be robust)

keithamus commented 6 years ago

In reality the polyfill is overkill anyway, you probably just want:

Object.defineProperty(Array.prototype, 'end', {
  get() {
    return this[this.length-1];
  },
  set(value) {
    return this[this.length ? this.length-1 : 0] = value;
  }
});