Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
In Javascript, is it acceptable to rename built in functions. For example, in my code, I use document.querySelector() tons of times. This is extremely long and tedious to type every single time (even with autocomplete from the IDE's side). Therefore, I decided to create a new function with a shorter name like the following:
let qs = selector => document.querySelector(selector);
Is this an acceptable practice in the JS community? Is this considered bad code? If so, why? Additionally, if doing this is alright, what are some drawbacks?
Thanks.
No.
Someone is going to come behind you to edit your code.
They will then have to track down your renaming function to actually see what it does.
Create an snippet in your IDE if it’s that much of an issue for you.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Hello guys I would like to use reactJS but it's not clear for me why do I have to use it, I already use Jquery and it works fine for me, I can use Java script and manipulate all the DOM the issue here is why? Why should i use it and what kind of things I can do with reactJS that I could not make with Jquery.
I hope you can give a hand or simple examples because I'm very confused thank you.
One of the biggest advantages is the component system for writing code. You can build all your html in blocks and then just import those blocks where you need them. You can also modify how those blocks are loaded using the component lifecycle for added control and optimisation.
These methods really help structure how you perceive information flow throughout your site.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
Is this a good practice? I mean is it good if all of my codes(behavior,presentation,structure) are inside on my .js(for example, since I'm making a website) file? Why? Sorry for my bad english.
Obviously it is not good practice, the recommended practice is to split all the code into its designated file. The simplest method is to use multiple script tags with src.
If you're really interested in dividing up your code efficiently, I would suggest learning BoostrapJS or AngularJS.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
Please ignore my syntax.
This is just an example if this is a bad idea.
let's say I have select with 50 options but instead of typing out options 50 times.
would it be a good idea to use js and give it an array variable.
run through the variable.length then append it into html.
Is it bad to use js like this though and why?
No issues. Now clients are way too much powerful than they were earlier before.
So, utilizing some of its power never harms.
Now the problem .. rendering template on client is not an issue ..Angular, React all does the same.
While you are doing only a little which may consumes less than < 1 ms. So , just go ahead.
it is a better practice.
You are a programmer, you will never need to type out options 50 times :)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm fairly new to Javascript, and filled with questions, most of which I'm able to find the the answers to online. However, there is the rare occurrence when my wording of a question doesn't correctly communicate the idea I'm trying to portray. That's when I come to Stack Overflow, and try to communicate more visually.
Which of these two examples is more commonly acceptable when programming with Javascript?
Method 1:
var one = 1;
var two = 2;
Method 2:
var one=1,
two=2;
Are there more specific (organizational) occasions when Method 2 should be used?
Example:
// Food
var pizza,
sushi,
cheeseburger;
// Utensils
var fork,
spoon,
excalibur;
Just in-case you believe the answer to this question is purely subjective, I pose a different question for you: which way (in terms of storage) is more efficient, and is the size of the difference insignificant for larger-scale web apps?
The virtual machine treats the two identically. There will be no performance difference between the two. Stylistically some developers prefer the former, while I have always used the latter. Ultimately whatever you find more readable and whatever is the communalized standard at your organization is the one to go with.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm coming from statically typed languages like C++ where there are tools (the compiler for one) that will remind me if I forget something obvious while refactoring. For example, if I change the number of arguments to a function but I forget to change all the calls to it. But it seems really easy to make this type of mistake in javascript. How do you avoid problems like this when refactoring javascript?
just like you do in c++/java. By writing tests.
Unit tests are the best. If you code is MVC, then you can certainly have unit tests with little effort, at least for the model layer. The benefit is you get feedback immediately. Check out QUnit
Functional tests via Selenium or equivalent are good too. They will find problems, but not immediately.
Only thing like that I can think of is: JSLint (http://jslint.com/)