1
vote
2answers
50 views

How to improve decode function

I have the next function: var decode = function(str, result) { var regex = /\d+/, number = regex.exec(str); if (number === null) { return str; } var start = ...
2
votes
2answers
47 views

Naming of overloaded methods - singular or plural? [closed]

This question is about your opinions and/or existing conventions. Let's say I have an object Basket that store various items in some private property (Basket._items). Now, I want to have a couple of ...
1
vote
1answer
178 views

Better jQuery function argument with if-statement?

function check_itv(key) { if (key.length){ if(key=="left"){ left_itv = setInterval(left,100); check_left= false; check_right=true; check_up=true; ...
2
votes
1answer
197 views

Refactoring this state machine (upvoting/downvoting)

I have a list of resources which can be voted on. There are 3 voting states: upvoted, downvoted and no vote. In a fashion identical to stackexchange voting, it follows these rules: If you upvote a ...
4
votes
3answers
444 views

Javascript function and global variables

I have a getValue function which just grabs some numbers from an HTML page – How can I access those variables in later functions without passing them down the entire chain of functions? As they sit ...
2
votes
1answer
262 views

Refactoring Javascript into pure functions to make code more readable and maintainable

Note: I am very new to Javascript. The code I provided is long but not complicated. The code below works and runs fine. But I would like to seperate it out into logical 'pure' functions to make ...
1
vote
2answers
683 views

calling functions over and over?! improvements needed

Not some much a problem, I am curious to know if my code can be cleaned up here a little. One annoyance is im calling a function three ( 3 ) times. I would like to know how this could be improved, ie: ...
2
votes
2answers
645 views

Setting variables inside an if else if statment and improving my javascript/jquery code

I refactored/rewrote my code to produce what is below and I am trying to work out if there is a more efficient way of doing it i.e. less lines of code and quicker etc. I am also wondering if it is a ...
4
votes
2answers
844 views

Do I always have to return something in an anonymous function?

I have inherited this snippet of jQuery JavaScript and am currently brushing up on my jQuery. NetBeans IDE complains that Anonymous function does not always return a value. So there is not always an ...