I know I can add comments like so:
//This is a comment,
/*so is this*/
But when I do this
/**comment?*/
It has a different color in my text editor (notepad++) and I was wondering whether it has any special meaning, or if it is just a random feature of notepad++.
Here is what it looks like in the text editor:
No, it has not any special meaning. It's more common to use that syntax when documenting code via comments.
The Java language supports three kinds of comments:
/* text /The compiler ignores everything from / to */.
/** documentation /
This indicates a documentation comment (doc comment, for short). The compiler ignores this kind of comment, just like it ignores comments that use / and */. The JDK javadoc tool uses doc comments when preparing automatically generated documentation. For more information on javadoc, see the Java tool documentation.
// text
The compiler ignores everything from // to the end of the line.
Not in JavaScript itself, but some editors will treat it like a JSDoc (https://github.com/jsdoc3/jsdoc) comment to help with autocomplete, etc.
You can also run your code through something like JSDoc to automatically generate HTML documentation for your codebase.
Probably notepad++ identifies it with two different colors just to diversify the type of comment. for a programmer a comment may be more or less important than another :)
might seem like a silly feature, but it is not
Related
Apparently no one else has wanted this feature, or I'm missing something. Intellisense works as normal, but I'm wondering if I'm missing a setting somewhere, if there is an extension, or if this functionality just isn't offered in VS Code... I would like to have the purpose of the method display when I start typing it as you can see in Adobe Brackets:
As opposed to how it shows in VS Code(which just shows the parameter requirements):
Is this possible?
VSCode is able to use the typescript language server to infer some information about the javascript that you're writing. The types for window/document etc are provided by the typescript team.
Here's where the type information for elements comes from. Compare that with the types for the document object. Notice that the properties here have comments above them, while the element properties do not. Type document.getElementById in VSCode, you'll see extra info like you do in brackets:
So for this information to appear about properties on Elements, someone would need to go through and add the comments. I have no idea if the typescript team is open to this, though.
It is so great that code completion is already there but two things are also important to have
1- refactoring ( renaming all the incidents of same variable/ function )
2- when you select a variable it to highlight all the occurrences of that variable
I wonder if the 1,2 are available yet as I need a JavaScript IDE to have both plus code-completion. I badly searched for all three Eclipse too. but then Eclipse doesn't have code-completion
1) Check out the "Rename JavaScript Identifier" extension. (The Replace All command built into Brackets is more powerful than what most text editors give you, but it's not a true 'rename refactoring' -- it's not type-aware and currently only replaces within a single file).
2) Check out the "Quick Search" extension.
I use Ternific ("JavaScript hinting and refactoring powered by Tern") which can do more than the above mentioned extension. Still renames on Ctrl+R.
Is there out any flag in the CoffeeScript compiler to add single-line coffee comments to Javascript output? I read some time ago it would be supported but it turns out this option still remains unavailable.
The easiest option is just to use block comments everywhere. A search/replace across your code base could take care of this in a trivially short time. You would change
# coffeescript one-line comment, not passed through to js
into this
### coffeescript block comment, which IS passed through to js ###
A harder option would be to mod coffeescript itself. For instance, the coffeescript lexer is very well documented, and shows that the logic used to identify block comments. By carefully modifying the lexer, I imagine you could convince it that your single line comments were block comments, which again, are already passed through to js. I haven't tried this, however.
You can do a single line comment by making it plain JS, eg.
`// this will appear in the compiled JS`
Whether you should or not is a separate question :)
I've been stuck with the unpleasant task of "unminifying" a minified JavaScript code file. Using JSBeautifier, the resulting file is about 6000 lines long.
Ordinarily, the variable and parameter names would be permanently lost, but in this case, I have an obsolete version of the original file that the minified JavaScript code file was generated from. This obsolete version of the original file contains most of the code comments and variable names, but absolutely cannot be used in place of the current version.
I would like to know if there is some way of renaming all instances of a particular parameter or variable in JavaScript. Since minification reduces the names to a single character, find-and-replace is impossible.
Is there some tool out there, which I can tell, in this file, the parameter a to function foo should be clientName and have it semantically rename all instances of that parameter to clientName?
Unfortunately, I work for a large organization with an approved list of software and I am stuck with Visual Studio 2010 for the forseeable future (no VS 2012).
Update: #Kos, we don't use Git, but we do use source control. The problem is that a developer who doesn't work for my organization anymore once made changes to the file, minified it, and only checked in the minified version to source control, so his changes to the original have been lost.
I'm a year late for this answer, but I had a similar problem to yours so I built this: https://github.com/zertosh/beautify-with-words. It unminifies code using UglifyJS2 but uses a phonetic word generator to rename variables. You get "long-ish" variable names so it's a breeze to do a find-and-replace. Hope this helps someone else!
You might have another way out.
Check out the last unminified version of the code. Compare to the minified version. Arguably most of it should be the same modulo consistent variable renaming. The differences you'll have to rename and remerge.
Diff won't do this kind of compare; you need tools that compare the programs as code, not text. Our SmartDifferencer tool will do this (by using language-specific full parsers to generate ASTs, and then comparing the ASTs); in effect, it compares the programs in spite of whitepspacing. SmartDifferencer also handles renaming; if two file are identical modulo a single renaming, that's what SmartDifferencer tell you.
I don't know how well this work work out; we haven't tried SmartDifferencer with 6000 lines of "consistently renamed" variables.
I found that a Visual Studio extension we've licensed here called "Telerik JustCode" has functionality to do what I want.
Which javascript major modes exist in Emacs, and what are their key-features ?
js2-mode: a new JavaScript mode for Emacs This is part of a larger
project, in progress, to permit writing Emacs extensions in JavaScript
instead of Emacs-Lisp.
Features: M-x customize Accurate syntax
highlighting Indentation Code folding
Comment and string filling Syntax errors Strict
warnings jsdoc highlighting
http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
With some documentation.
I think what you want is this:
http://www.corybennett.org/download/javascript-mode.el
Then again, maybe this what you are looking for?
or this?
People seem to prefer (at least given the highest rated answer):
Updated: http://steve-yegge.blogspot.com/2008/03/js2-mode-new-javascript-mode-for-emacs.html
I use Steve Yegge's js2-mode, and like it a lot. It's quite configurable, its indentation ideas match mine, and most impressively it has a full JavaScript parser in it, so it can alert me to syntax errors as I type (indispensable for little things like trailing commas in property lists that bork IE).
Espresso mode is supposed to be quite good as well.