Hello, JS Nation. Welcome to the future features of JavaScript. In this talk, we will be going through different proposals from stage 0 to stage 3, understand why they exist, what they are trying to solve, and hopefully, they get implemented in all of the JavaScript environments.
I'm Hemant. I'm an Engineering Manager here at PayPal, a TC39 delegate, a Google developer expert for Web and Payments Domain. You can hit me at Newman on Twitter or find me on html.com. The ECMA International has a lot of technical communities, out of which TC39 happens to be the ECMAScript community, which is responsible for the specification that JavaScript implements. The TC39 process includes different stages, starting from Stage 0 to Stage 4, where Stage 4 is finished and implemented in different environments, and Stage 1 is more like a strawman with just a basic idea of what the proposal is. In this talk, we will go from Stage 0 to Stage 3 and see different proposals.
If we look into the current state of how the proposals are, on Stage 0, we have 18 proposals. On Stage 1 we have 91 proposals, and Stage 2 we have 22, and Stage 3 we have 17, and Stage 4 we have 59 proposals. Let's dive into and surprise ourselves with some of these proposals, starting with Stage 3.
Say we have an array of objects and you want to find a particular value from the end of the array. What would you do? You would probably do a reverse on that array and do a find. In this case we're trying to find the values which are not divisible by 2. And in this case we got value as 3, but we had to reverse the array and then do a find. What if we had a convenient method which says, array.findFromLast, array.findLast, here is the condition, give me the element. What if you were to find the last index? You would again do a reverse and do a find.index, and take the array.length and subtract minus 1 from it and subtract that value from whatever we found if the result is matched to find the index. In this case the value was 2. Suppose the condition is not met, where we are looking for number 42. The value should have been minus 1, but it is 4. What if we had a method that said, array.findLastIndex, and when the condition is met it will find the index if it's present, and if not it would give minus 1. Wouldn't it be convenient? Here on the left is a comment from one of the issues in GitHub for this proposal where the idea was to discuss and come up with names. As you can see, some of the names that were popped up in the issue was like findRight, findIndexRight, findLast, findIndexLast, findEnd, findIndexEnd, and so on. Finally we have findLast, and last, findLastIndex as the proposal today. On the right side we can see an implementation from the Chromium source which says fastArray findLast. If you want to open up spec, you could do a one on one mapping to each of those lines in this code to understand how the specification is implemented. For example, on the comment where it says 4, that's point four in the spec which says let k be length minus one, and that's where we have the exact implementation here. That is findLast and findLastIndex. Then we have import assertion.
Comments