theforumhelpers.github.io
theforumhelpers.github.io copied to clipboard
Simplify FHP.js and use code supporting modern browsers
We currently implement the fetch
standard, which is present starting Chromium 42 and Firefox 39.
In FHP.js, we can really simplify it a LOT, and use better code practices supported in these versions, such as:
-
document.createElement
instead of Element.innerHTML - XSS could be a thing, but moderation is implemented in the main website. Really, you should just use.innerText
, It's supported in most browsers. - Use
const
orlet
instead ofvar
. The declarationvar
isn't really good (search it up on google, there are loads of things). - Use
for .... of ....
iterators instead offor (j = 0; j < ....
iterators. It's supported in most browsers, and we really don't need the index of the member in the array. - We shouldn't keep calling
document.getElementById(string)
every single time we need to update it in the same section of the code. We should just declare a variable!
I hope you take this into consideration, as this would introduce new JavaScript programmers to better solutions for code, instead of old ones.
document.createElement in FHP.js would make it a lot more verbose, and I don't think XSS is as much of a risk for such a simple, relatively low-traffic site like this
Yeah, I’ve heard that let
is sometimes better than var
And I always use const
for things that don’t change - it’s just better (it doesn’t let you change it I think) in my opinion.
does it really matter in the case of this repo tho?
@gosoccerboy5 It probably won't impact the actual site. I guess it's just a code improvement.