Creating your own JavaScript

  • Revert back to React.createClass - no practical cons, but you are relying on a magic that createClass does and don’t use the standard class.
  • Use .bind on methods in the constructor or in the render - a lot of manual boilerplate. Binding in the constructor does not work with React Hot Loader and binding in the render creates a new function on every render.
  • Use arrow functions with class properties. This is not-yet-standard JavaScript feature, but can be used with babel stage-0. Compiles down to a method binding in the constructor, so still not hot-reloadable.
  • Make JavaScript classes automatically bind methods by changing the language itself. Pros and cons are discussed bellow.

Rethinking best practices… again

--

--

--

Building software that builds software. Automation, AI, compile-to-JavaScript tools

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Karolis Masiulis

Karolis Masiulis

Building software that builds software. Automation, AI, compile-to-JavaScript tools

More from Medium

React Router v6

Redux Basics

A reducer function that takes a state and an action, determines what to do based on the type of action and returns a new state

Get start with react js

Building A Simple Temperature Converter Using Javascript and React.js