4 ms·
In the list of useful functions I'd accumulated over a few years of JS, there are `[].last` and `[].lastIndex()`. The former is a property getter/setter implan
by MarsAscendant 8y ago
In the list of useful functions I'd accumulated over a few years of JS, there are `[].last` and `[].lastIndex()`.
The former is a property getter/setter implanted into the Array object¹. The latter is a function that returns `[].length - 1 || 0`.
¹ I know planting properties and functions directly onto the basic objects is generally frowned upon, but I see no harm in doing that for personal projects. Using it in the big-web production might be verboten, but it doesn't I can't make my coding life a bit easier.
Meanwhile, I have a problem with the "web compatibility naming safeguard" argument over the names of the proposed properties/functions. Surely, the websites using `[].last` override the namespace to begin with. If, say, `[].last` were to be accepted, how could it break the sites using the override version?
Outside of that, the fact that new proposals have to cow before a widespread conventional use of the names renders me confused. I feel like the JS engine should take priority over mere convention. Sure, some websites might be hurt in the process, but at least the generations of current and future coders would have few problems figuring out what the new functions do.
Exhibit 1: `globalThis`. Nuff said?
Exhibit 2: `[].smoosh`, which apparently was in the books [https://github.com/staltz/prevent-smoosh https://github.com/staltz/prevent-smoosh]. No longer is: it's now `[].flat`.
Exhibit 3: `Math.clamp()`, in questions [https://github.com/rwaldron/proposal-math-extensions#questions https://github.com/rwaldron/proposal-math-extensions#questio...] for the `Math` extension proposal. (Yet undecided-upon.)
`[].last` just makes sense.