I prefer the original one.
I don't see the value, for this use case, of all those checks. We know what the input values are, essentially what's in the DOM that we 100% control.
I feel ES6 syntax much less readable than ES5 (probably because I have worked more in ES5 than ES6), it introduces a bunch of new symbols.
How can this
const isNull = x => x == null
Be more readable than
function isNull (x) { return x == null}
Another example,
const addClass = (el, className) => {
}
I always have to remember what this construct means and translate / unroll it in my mind to a regular function.
Also, why would an addClass return a boolean? Doesn't make much sense.
// $ :: String -> HTMLDocument -> HTMLElement
const $ = (id, _document = document) => {
if (isNullOrEmpty(id)) return null
if (isNull(_document)) return null
return _document.getElementById(id) || null
}
How can above be more readable than
function $(id) { return document.getElementById(id); }
I bet I can give the original code for Python/C/Java developers and they would understand / change it easily.
That said, I consider myself a backend / devops person who sometimes needs to do work in the frontend, the biggest
project I did was a medium size app with around 40 routes that I used react, es5 and bootstrap.
Big fan of Go and it's very readable / limited syntax.