Tagged Questions
1
vote
2answers
3k views
Setting variables inside if / else-if statment blocks
I have written the code 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 whether it is OK to declare ...
2
votes
0answers
142 views
jQuery animate opacity, fade, & slide up page load effect
This is the first time I've actually made my own jQuery script from scratch, because I couldn't find exactly what I was looking for. My code works how I want it to, although I don't know if I did it ...
4
votes
1answer
81 views
Fix base64 data URI scripts function
So I noticed Chrome has quirky behaviour when it encounters script tags whose src is a base64 value. I decided to write a quick ...
0
votes
2answers
48 views
Trying to convert an extended Array.prototype to a function
I got a random image rotator working by using the following script (demo). But I was told that it is a bad practice to extend Array.prototype. And it does. It ...
8
votes
2answers
118 views
Advice needed for scopes in JavaScript
I would like to connect this "JS" to Bugzilla (example: bugzilla.mozilla.org or landfill.bugzilla.org).
I started to learn JS language today and I would like to ask you:
How can I not do bad ...
6
votes
1answer
129 views
Parsing function is 50 lines long
This is a parsing function that will at tildes (~) to end of search terms in certain circumstances.
Example an inputs and outputs:
Input: Output:
name:(john doe) ...
6
votes
3answers
85 views
Functions that return a variable
I'm simple looking for what the general preference is between the below options:
anon function directly to variable
...
3
votes
1answer
62 views
Math Skills Game Advice
I think my code works pretty well, although I'm biased: http://jsfiddle.net/AHKb4/2/
Basic Overview: I'm working on building a math skill game, where the objective is to drag and drop div's to a ...
5
votes
3answers
3k views
JavaScript functions 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 ...
3
votes
1answer
101 views
I'm torn between conditionals and abrupt return functions
Which one of these two is better?
This one:
...
2
votes
2answers
151 views
Deeper abstracting of code into functions
I created a quiz using the module pattern. My code is as follows:
...
0
votes
2answers
198 views
Extending DOM elements with prototype for easier function execution
So I've creating a small library of JavaScript functions that I will be using. Some are for UI functions others are to return something. Below I will post two codes, I am wondering if this method is ...
4
votes
1answer
128 views
Generalized is() type-checking function for JavaScript
In a complex library I've been working on, I got pretty tired of all of the individual type functions and operators to determine whether I was working with an object or piece of data of a given type. ...
1
vote
2answers
66 views
3
votes
3answers
101 views
More efficient version of an ID calculator in JavaScript
The following function takes two numbers that are linked with a "user" and calculates an ID number based on that. I have been trying to make this as clean as possible, and would like some advice on ...
1
vote
2answers
92 views
2
votes
2answers
92 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 (...
1
vote
1answer
480 views
2
votes
1answer
278 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 ...
5
votes
2answers
2k 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 ...
2
votes
1answer
472 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
713 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: ...