In Javascript for some methods, I don't see the suggestions. For example indexOf, charCodeAt and so on. Is it possible to activate suggestions for these built-in Javascript keywords?
I think you should leverage VS Code ability to work with JSDoc.
As you can see without JSDoc, VS Code can't infer that bar is a string. After documenting the parameter properly, it is able to make some meaningful suggestions:
Related
I am inspecting some code on Github and I need to quickly understand if the script is javascript or typescript.
Are there any easy shortcuts or clues to this?
As an example, in this image from https://www.typescriptlang.org/ gives me a clue that if an array is declared with a bracket [] after the variable name, then it is typescript.
You can distinguish between the two formats by looking simply at the functions.
Are any of the functions specifying types such as 'string,integer,object,array,function?...' etc?
In traditionally javascript this is not allowed.
Best,
AT
Also as others may have pointed out, you can also check the file extension
I'm a student who's capstone project/work intergrated learning is about to end. I'm working on producing technical documentation to hand off to the next team that will continue on with this work, but I've hit a snag.
My class methods that use arrow functions aren't generating params documentation when I create documentation using the jsdoc tool.
i.e.:
becomes
The documentation works as intended in visual studio code/intellisense:
I've been googling around to try and figure out what the problem was, but I failed to find anything.
I mean, my research yielded:
Outdated way to make vscode play nice with arrow function
syntax: (https://github.com/Microsoft/vscode/issues/36283) (https://github.com/Microsoft/vscode/issues/22264) ((This one is the actual issue where the support was added) https://github.com/microsoft/TypeScript/issues/14134)
Outdated info on the jsdoc support for this feature:
https://github.com/jsdoc/jsdoc/issues/1310
etc., etc., again, nothing useful.
Of note is that I'm using the jsdoc-export-default-interop plugin so that jsdoc will actually generate things for export default [CLASS OR FUNCTION].
I've found a solution that fits my requirements
However, while it is good enough for my purposes, I'm not entirely sure it's acurate and would be happy to hear critisims, other people's viewpoints and solutions. I'll explain the concerns I have at the end.
The problem: It looks like jsdoc cannot automatically detect if a member assignment is a function when parsing.
I have no idea why VSCode is able to detect it automatically, but it appears the JSDoc tool cannot. Here it is stated in the official documentation
Link to documentation: (https://jsdoc.app/tags-function.html)
The solution: Document the member with the #function tag (or an alias like #method).
By documenting the class member with the #function tag like so:
I am able to get the arrow function to generate as a class method, and get params documentation:
My concerns
Well the biggest concern/annoyance is now I need to go through all the source code and add a bunch of #function tags. Ah whelp.
Other concerns are that I may have misunderstood the problem/I'm not quite sure if this is best practice.
And I'm not too certain if this documentation is accurate in terms of if there is actually a tangible difference between a class member arrow function and a class method that I need to capture in the API documentation.
Anyway, I think this will be what I go with, but I'll be monitoring this answer to read any input/feedback :)
Looking through the promise code in v8 source code, I noticed a lot of functions that starts with %, what are those? do they have any special meaning?
example here https://chromium.googlesource.com/v8/v8/+/3.29.45/src/promise.js?autodive=0%2F
like %DebugPushPromise
They're internal built-in runtime functions. More info here: https://v8.dev/docs/builtin-functions
I'm trying to enjoy some of the awesome javascript code golf submissions on anarchy code golf, but I keep seeing things like:
for(;s=readline();)print("h"+/t.*/(s))
...which was the JS winner for: http://golf.shinh.org/p.rb?ttp
I don't understand how that is correct javascript syntax, and I even tried resubmitting that, but it said object is not a function, which is something along the lines of what I would expect to happen.
Was this some kind of glitch or shorthand or something in an older javascript version?
Was this some kind of glitch or shorthand or something in an older javascript version?
More or less, yes. According to that site's version info, it uses SpiderMonkey (Mozilla's JavaScript engine), which used to have the feature that regular-expression objects were callable; that is, that if re was a regular-expression object, then re(...) was equivalent to re.exec(...). That feature was removed in this change, a result of Bug 582717, and that site has since updated to a version that incorporates that removal.
I've tried some of the editors/IDEs regularly recommended for coding JavaScript (Aptana, WebStorm, ...) but none of them has a satisfying autocomplete functionality. I'm probably spoiled by Microsoft's IntelliSense for .NET. There is some JavaScript-IntelliSense in WebDeveloper, but that seems to be a stripped-down version. The best I've found so far is WebStorm, but its code completition is easily distracted by imported libraries (offering hundreds of suggestions) and identical function names.
Did I miss an editor/IDE that uses refactoring (or something else) to offer proper code completition, so that it really "knowns" what that variable-name stands for, I just put a dot behind? Or is something like this on its way?
I always recommend Komodo Edit from ActiveState (now up to version 6, with support for HTML 5 and CSS3 as well as recent versions of Javascript, PHP, etc.) Note that you may have to install addons for the languages you're working in, but you should find them through the Mozilla-like Addon manager.
Also supports jQuery and even lets you use jQuery (along with vanilla Javascript or Python) in its powerful macro IDE.
Code completion example:
<script type="application/x-javascript">
var obj = {};
obj.personnel = [{firstName:"John", lastName:"Brick", age:43},
{firstName:"Jane", lastName:"Motte", age:26}
];
// now type obj. and code completion immediately offers you "personnel"
// note: file must be saved for the app to find all members of declared
// variables, but I save about every 10 seconds so it's not a problem
</script>
The best I've found so far is
WebStorm, but its code completition is
easily distracted by imported
libraries (offering hundreds of
suggestions) and identical function
names.
This comment confuses me. If you import the libraries, and your code is using them, why is it bad to include the function names in the code completion suggestions? Wouldn't you want to have jQuery's functions included if you're using it?
If you're using Microsoft's IntelliSense with jQuery, does it stick to its guns and only show JavaScript core functions? Sounds limited to me, unable to be smart when I add libraries.
Or is something like this on it's [sic] way?
It sounds to me like you want a clairvoyant interface. I don't think it is on the way anytime soon.
By the way, "it's" == "it is"; "its" is the possessive.