This site runs best with JavaScript enabled.

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('');
},
});
}
Share article