R
R
retyui2015-10-06 12:08:25
JavaScript
retyui, 2015-10-06 12:08:25

Javascript code refactoring?

Tell me how you can improve the following code (coffeescript)

text = "Отправка"
          textanim = setInterval ()->
            if text.length > 10
              text = text.slice(0,8)
            else
              text+="."
            subBtn.text(text)
          ,500

analog js
var text, textanim;
text = "Отправка";
textanim = setInterval(function() {
  if (text.length > 10) {
    text = text.slice(0, 8);
  } else {
    text += ".";
  }
  return subBtn.text(text);
}, 500);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Danilov, 2015-10-06
@Danand

At a minimum, you need to remove the magic numbers somewhere .

H
HoHsi, 2015-10-06
@HoHsi

canonText = "Отправка"
text = canonText
dotCount = 0
textanim = setInterval ->
    if dotCount > 3
        dotCount = 0
        text = canonText
    else
        text+="."

    subBtn.text text
    dotCount++
,500

Use Coffee more tightly
PS why refactor such nonsense?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question