JavaScript is the language of the web, and it’s quickly becoming the language of choice for developers who want to build web applications. But that’s not to say that JavaScript is a perfect language; there are still some areas where it can be improved. One area where JavaScript can still be improved is in its support for event handlers. Event handlers are a powerful way to handle events on your page, and they can be used to add interactivity and functionality to your pages. But while event handlers are a great way to add interactivity and functionality, they can also be difficult to use. They can take up a lot of code space, and they can also be difficult to read. So how do you use event handlers effectively? And what are some tips for using them effectively? Here’s an example of how you might use an event handler: // Add an event handler for the “click” button on the page window // The handler will take two arguments: the button’s id and the value that was clicked // The first argument will be used as the context object for the click event // The second argument will be used as the result object (the value that was clicked) function clickHandler(id, value) { this.id = id; this.value = value; } window.addEventListener(“click”, clickHandler, false); The first step in using an event handler is to determine which button was clicked on by checking their id property. This will give you information about which button was clicked on by accident or by someone who didn’t know what they were doing when they clicked it. The next step is to create a function that will handle the click event on that button: function clickHandler(id, value) { if (!this[id]) { return; } this[id].value = value; } window.addEvent


Most websites and web applications are written in JavaScript, or at least something that is converted to JavaScript. There have been many attempts over the years to change that, but don’t expect JavaScript to completely go away anytime soon.

Zaplib is a startup company that created a framework for rewriting parts of JavaScript-based web applications in the Rust programming language, which would then run in web browsers using WebAssembly. Rust is a low-level programming language optimized for performance and safety, and many applications have used Rust to significantly improve load times and responsiveness. Mozilla rewrote the CSS engine in the Firefox web browser using Rust in 2017, as part of the ‘Firefox Quantum’ update, which doubled Firefox’s typical performance. WebAssembly allows sites to write their code in more traditional programming languages, like C++, and run it inside a web browser just like JavaScript.

Zaplib hoped that rewriting web applications in Rust-powered WebAssembly, one section at a time, would result in performance boosts as much as 10x. However, the company’s founders said in a ‘post-mortem’ that the massive jumps didn’t quite pan out. “Our bet was that it would be 10x more ergonomic to speed up your app, incrementally, in Rust. This did not hold up in real-world implementations,” the team said.

The group noted a few problems with its plan. Most companies were (understandably) hesitant to rewrite their code in a language their engineers might not have been familiar with, but more importantly, there wasn’t a significant speed difference between good JavaScript code and good Rust code. Zaplib helped one company port a simulation tool to Rust, which only ended up being 5% faster than the existing JavaScript version. Zaplib also hoped its hardware-accelerated 2D renderer would help, but most of the performance boost there came from WebGL, which doesn’t need Rust or WebAssembly at all.

This doesn’t mean WebAssembly is terrible or unhelpful — Google Earth and Photoshop were both ported to web browsers thanks to WebAssembly, and companies like Microsoft are building frameworks for more developers to make the same transition. There’s absolutely a reason for it to exist, but JavaScript has also evolved significantly in the past few years. The ‘V8’ engine that handles JavaScript code in Chrome, Microsoft Edge, and other Chromium-based browsers is constantly becoming faster. Recent optimizations made Chrome the fastest web browser available on the Mac, according to Google, and other changes have sped up the Windows and Android versions too.

WebAssembly is already bringing a new wave of applications to the web that couldn’t have existed a few years ago, but don’t expect all JavaScript to go away anytime soon. Zaplib said in its post, “there are usually simpler ways to find performance improvements than Rust [or WebAssembly].”

Source: Zaplib