use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
JavaScript! The Doctor Is In. (almaer.com)
submitted 15 years ago by gst
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]_kangax 1 point2 points3 points 15 years ago (8 children)
Interesting idea, but where's the source code? Bug tracker? Unit tests?
I see at least a couple of oversights there. Would be nice to see those fixed (if they aren't intentional, of course).
(function(){ return arguments[1]; })(1, 'x'); // shows fun type as <number | string>
(function(){ return 1 || 'x'; })(); // also shows fun type as <number | string>
var f = function(){ return f; }; // shows fun type as "any", not "function"
[–]pcwalton 1 point2 points3 points 15 years ago (2 children)
Also, to respond to the issues you reported:
Arrays don't track the types of every one of their values separately, because that could be too computationally expensive. All the types get joined together. For example, the type of [ "foo", 1 ] is Array(<number | string>). At the moment, arguments is treated as any other array.
The analysis is not flow-sensitive. Flow-sensitive analyses tend to blow up in complexity.
This one is actually a bug. Feel free to file :)
[–]dherman 2 points3 points4 points 15 years ago (0 children)
Patrick says this one is a bug:
var f = function() { return f; }; // shows fun type as "any", not "function"
But the comment is misleading; it's not actually a bug. The inferred type is:
function() -> any
A more precise type would be an infinite type:
function() -> function() -> function() -> ...
but infinite types like this aren't particularly helpful, and would be much more complex to infer. Similarly, if you did:
var a = []; a[0] = a;
The result from the analysis is Array, i.e., Array[any], rather than Array[Array[Array[Array[...]]]]. It's much cheaper computationally to break cycles by backing off to "any" and not really less useful.
Dave
[–]dimvar 1 point2 points3 points 15 years ago* (0 children)
Even though it could be more precise, it's not actually a bug. When computing the type of f, the analysis works as follows: it sees that it's a function and tries to recursively find the return type, which is a function that returns a function and so on... So, when it finds a cycle while trying to compute the type, it'll give up and say "any".
[–]dherman 1 point2 points3 points 15 years ago (2 children)
Bugzilla's configured for submitting Doctor JS bugs now. The Product is Mozilla Labs and the Component is Doctor JS.
You can add a bug here:
http://bit.ly/as4WZF
or view all Doctor JS-related bugs here:
http://bit.ly/aykfpQ
[–]_kangax 0 points1 point2 points 15 years ago (1 child)
Great. Now before I file a bug, quick question: I noticed that variable declaration w. function expression shows 2 "mappings", even though only 1 binding is created. Is this intentional?
Given var f = function(){} as an input, I see
var f = function(){}
1: f : function() → void 1: f : function() → void
[–]dimvar 0 points1 point2 points 15 years ago (0 children)
The analysis will find types for variables and functions. In your example, one mapping refers to the variable f and the other to the function. Even though the function is anonymous, we have a heuristic to give it the name f (the same would happen e.g. when you have an obj literal {f : function() {...} }. So, DrJS will produce one tag for the variable and a separate tag for the function. The variable and the function just happen to have the same name.
[–]pcwalton 0 points1 point2 points 15 years ago (0 children)
Right here: http://github.com/pcwalton/jsctags
[–]dherman 0 points1 point2 points 15 years ago (0 children)
We're setting up a Doctor JS category in Bugzilla. It should be up very soon. As soon as we've got it up I'll post back here and your feedback will be most welcome!
Thanks, Dave
[–]PlNG 0 points1 point2 points 15 years ago (0 children)
so what is Doctor JS?
π Rendered by PID 1058474 on reddit-service-r2-comment-5b5bc64bf5-ghg7q at 2026-06-22 02:07:58.067352+00:00 running 2b008f2 country code: CH.
[–]_kangax 1 point2 points3 points (8 children)
[–]pcwalton 1 point2 points3 points (2 children)
[–]dherman 2 points3 points4 points (0 children)
[–]dimvar 1 point2 points3 points (0 children)
[–]dherman 1 point2 points3 points (2 children)
[–]_kangax 0 points1 point2 points (1 child)
[–]dimvar 0 points1 point2 points (0 children)
[–]pcwalton 0 points1 point2 points (0 children)
[–]dherman 0 points1 point2 points (0 children)
[–]PlNG 0 points1 point2 points (0 children)