What's new in ES 2020?

As we near the end of the decade, I'd like to share with you some of the upcoming changes to JavaScript that are coming in 2020. These are all currently Stage 5 TC39 ECMASCript Proposals.

String.prototype.clap()

Sometimes you really need to explain something to the user. In ES2020, you'll be able to use the new .clap() function. This will both capitalize a string and inject the "clap" emoji (👏) between spaces or the separator of your choice.

'21:9 should be called 7:3'.clap();
// => 21:9 👏 SHOULD 👏 BE 👏 CALLED 👏 7:3"

"Epstein didn't kill himself".clap();
// => "EPSTEIN 👏 DIDN'T 👏 KILL 👏 HIMSELF"

Polyfill

// String.prototype.clap() Polyfill

if (!String.prototype.clap) {
  Object.defineProperty(String.prototype, 'clap', {
    value: function(separator, limit) {
      return this.trim()
        .toUpperCase()
        .split(separator || /\s/, limit)
        .join(' 👏 ');
    },
  });
}

Array.prototype.boomer()

This new utlity function can be chained to any Array prototype method to give it a short-lived performance boost. The one trade-off is that using .boomer() will use more and more of your user's CPU until the computer or device overheats and ultimately crashes. Use with caution.

new Array(10000).fill('_').map((_, index) => console.log(index));
// 100ms execution time

new Array(10000)
  .fill('_')
  .map((_, index) => console.log(index))
  .boomer();
// 50ms execution time

Unfortunately, no polyfill is available at the time of writing.

String.prototype.sarcasm()

Another new string utility that will change a string's casing by alternating between upper and lower. Really great for error messages and really anytime you want to make someone feel inferior to you.

'Use the platform'.sarcasm();
// => "uSe ThE pLaTfOrM"

'Gushers are actually just soup dumplings'.sarcasm();
// => "gUsHeRs aRe aCtUaLlY JuSt sOuP DuMpLiNgS"

Polyfill

// String.prototype.sarcasm() Polyfill

if (!String.prototype.sarcasm) {
  Object.defineProperty(String.prototype, 'sarcasm', {
    value: function(separator, limit) {
      var upper = this.trim()
        .toUpperCase()
        .split('');
      return this.trim()
        .toLowerCase()
        .split('')
        .map((el, i) => (i % 2 == 0 ? el : upper[i]))
        .join('');
    },
  });
}
Jared Palmer headshot

👋 Hey! I'm Jared Palmer. I'm currently the Director of Developer Tools and Frameworks at Vercel where I lead the Next.js/React, Svelte, Turbopack, and Turborepo teams. I joined Vercel after they acquired my build system startup Turborepo in late 2021.

Jared Palmer © 2023