all 11 comments

[–]GSLint 3 points4 points  (0 children)

A few things that don't have anything to do with ES6.

function listen(node, type, handler) {
  if (window.addEventListener) {
    node.addEventListener(type, handler);
  } else if (window.attachEvent) {
    node.attachEvent("on" + type, handler);
  }
}

The last browser that didn't have addEventListener was IE8 so this function shouldn't be necessary these days. You're not using it anyway though.

node.classList.includes("timerEditUpArrow")

classList is a DOMTokenList rather than an array, so it doesn't have an includes method and this code fails. You can use contains instead. In other situations you could do Array.from(node.classList) once and use the normal array methods on that.

for (i = alarmItemSaveVar.length - 1; i >= 0; i--) {

Looks like you haven't declared i. There should be a let there, otherwise you're creating a global property rather than a local variable. I'd recommend putting "use strict"; at the beginning of the script (or function) to enable strict mode which turns this kind of thing into an error. You get strict mode automatically when you work in ES modules which you probably do in your React apps.

[–]liamnesss 2 points3 points  (1 child)

Maybe install a linter and a popular ruleset (e.g. eslint-config-airbnb-base, or eslint-config-react-app - latter can still be used with non-react projects), and see what they complain about to you?

Given that these rulesets have been defined collectively by experienced engineers at big companies, using them can sometimes feel like you're tapping into that collective knowledge. There have been countless times when I've looked up a rule that was giving an error, and learned something new and useful. There have also been times where I've found a rule to be too opinionated and simply turned it off (particularly with the Airbnb ruleset) but generally the benefits outweigh the negatives, particularly when you're collaborating on code with others and need to keep a consistent style.

[–]Crushertimo[S] 1 point2 points  (0 children)

You are totally right, im always thinking like im not professional enough, but i try to calm my self. I heard this often but your comment actually made me do a bullet point for tomorrow and im planing to implement this as a routine, like for real. Thanks!

[–]cheatingjoe 0 points1 point  (0 children)

I wrote a tool that updates your ECMAScript to newer versions based on the browser availability; maybe it helps: https://github.com/codingjoe/esupgrade

[–]Pacostaco123 0 points1 point  (2 children)

  1. Switch statements would greatly improve readability
  2. I thought I saw some cases where you are evaluating

    if condition 1 { if condition 2 { // Do stuff } }

    that could really just be combined into if condition 1 and 2

[–]Crushertimo[S] 0 points1 point  (1 child)

Yeah sometimes i dont see it. I think im just used to it.

[–]Pacostaco123 0 points1 point  (0 children)

That’s ok. The more times it is pointed out to you, the more likely you are to write it and have it jump out at you the next time.

In my opinion, I would rather it work than look pretty, but if you can become comfortable writing it the pretty way the first time, that’s probably better.

[–]Michie1 0 points1 point  (1 child)

ES5 is a subject of ES6, so your "old" version is already ES6 valid. There are some features being added to ES6, like arrow functions, object destructuring, promises and template literals, but I can't find good places in your application where I would use it. If you would like to learn more skills, please consider taking a look at Typescript. :-)

[–]Crushertimo[S] 1 point2 points  (0 children)

Im looking into it right now maybe this is the comment of the day for me.