Parenthesis placing after function [closed] - javascript

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
Which is the common best practice for where to place parenthesis after a function? I see at times function () and I see function(). With parameters I see function (param) and then I see function(param. Is this just a matter of preference or is there a reason as to why there would be whitespace after the function or there would not be whitespace?

JavaScript is not white space sensitive.you define your coding style.
Though having white space between the function and parenthesis is no sin. If you follow crockford's javascript standards. He advises not to have space in between.
http://javascript.crockford.com/code.html#function

The size of the indent is usually independent of the style. Many early
programs used tab characters for indentation, for simplicity and to
save on source file size. Unix editors generally view tabs as
equivalent to eight characters, while Macintosh and Microsoft Windows
environments would set them to four, creating confusion when code was
transferred back and forth. Modern programming editors are now often
able to set arbitrary indentation sizes, and will insert the
appropriate combination of tabs and spaces. For Ruby, many shell
programming languages, and some forms of HTML formatting, two spaces
per indent level is generally used.
Read full on Code Indent Style in Programming

Related

How to apply comment style to text pieces which may have overlapped parts? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
The community reviewed whether to reopen this question 1 year ago and left it closed:
Original close reason(s) were not resolved
Improve this question
Say I have a contenteditable div with text contents. Now I want to add comments (which are outside the container div) to some pieces of the text. And when the user clicks the comment, the corresponding text pieces should be styled (e.g. red color). The difficulty is that these pieces may have overlapped parts (like ab and bc in abc).
And I want the style applied based on the very characters starting and ending a sequence. So if new contents (even if the same pieces) are added before the starting character or after the ending character, the style will not be applied.
To split each overlapped part into a new element may help but seems not that clean (especially when the contents contain many nested tags). Are there some better ways?
Tags must be nested, so you should use something like splitting.js. Two problems are, with content-editable they could drag-drop anything (so id's may be lost), and the eventListener could fire multiple times (so be careful with regex). I doubt that your intent to intercept content-editable is generally enforceable. As you juggle multiple, complex, nonstandard scenarios, how does the user benefit?

How Does Javascript if statement indentation work? [closed]

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
How many spaces should be used for each line of if statement at the beginning of the line?
suppose we have 10 lines of nested if statements, what is the formula to determine how many lines to be used? Also can a programmer use the tab key instead to obtain proper indentation for a statement.
if (a !== 0) {
if (b > 1) {
if (c < 1) {
Indentations and spaces is not a requirement it just helps your code to be more readable.
Unlike languages like Python in which whitespace is considered semantic by the compiler, the Javascript compiler ignores runs of whitespace altogether. In my experience, though, the most common indentation (tab) lengths are 2 spaces and 4. My personal preference is 4, but plenty of other people will say 2.
I will say, though, that if you're using more than 4, you're either going to need to break your more nested logic up into multiple lines, or you're going to end up with a lot of overruns -- even with only 4 spaces, I often find myself running over 80 characters.

What is the maximum number of tags should contain a page that does not significantly slowed down? [closed]

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
I need to create a project of web application that contains a very long list of items and I can't use pagination...
How many tags is optimal for the single website from the point of view of the optimization?
When the website begins to slow down due to the large number of tags?
How do you deal in a different way than the pagination?
Can you suggest a javascript library free for commercial use?
As mentioned by #gus27 it all depends on what operating system, browser and most importantly the resources such as CPU and memory that is available to the browser for use.
Having said that, modern browsers can easily handle 100s if not 1000s of tags. The best way to go about optimization is to go make the system and when you hit a bottleneck try to find out the reason for it and then fix it. Don't worry about efficiency until you hit a problem which requires optimization.
Angular.js is the javascript that comes straight to my mind for the kind of javascript library that i think you want.

Is there a text editor API providing numbers of lines for enclosing block? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I have an idea of a cool tool for pretty much any text editor. To implement my idea I need to be able to:
Find the beginning and the end of the block of code where a statement is located. The number of lines for the declaration of the function and the corresponding closing bracket in JavaScript would be the dream.
Find every occurrence of the specified variable in a file.
This requires some syntax analysis of the target language. I really don't have much preference for the language of the API and the language being examined. Is there an easy-to-use tool for this?
I've been Googling this question for some time, and haven't found an obvious answer for the easiest way to do what I want. I only have opening code for Eclipse's editor to find the solution in mind right now. Atom's scope Descriptors seem unwilling to return numbers of lines for scope declarations.
I found out that I needed a proper parser for the target language to build a syntax tree of a file. I ended up using the esprima parser for JavaScript in combination with the Atom text editor, both of which are easy to delve into.
Also, it seems that the Python compiler provides an easy way to build an AST for Python code.

JavaScript: Why single and double quotes still live together? [closed]

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 9 years ago.
Improve this question
I am beginner in JavaScript and I am wondering why string literals with single and double quotes still live together? There already was a discussion on StackOverflow about which are better to use in certain situations, but why a majority of other languages do not have such feature, despite it is still an official JavaScript standard? It is much interesting to know - I do not believe this feature is some "rudimentary" stuff left from older versions. Thorough explanations are appreciated.
I am wondering why string literals with single and double quotes still live together?
I'm not following your "still" in that sentence. JavaScript was originally defined to have two kinds of quotes so that it's easier to do quoted quotes, and there's no reason to change that. There are lots of reasons not to change it. (Not least that it's useful. But also removing it would break a truly huge amount of code.)
...why a majority of other languages do not have such feature...
In most languages syntactically derived from B (as JavaScript is, like C, C++, C#, and Java), single quotes are used for character literals. But JavaScript doesn't have characters, just strings, so the single quotes aren't needed for that purpose.
...despite it is still an official JavaScript standard?
Yes, it's in the specification and that won't be changing.

Categories