Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a way to format JavaScript object and function parameters differently in IntelliJ?
    primarykey
    data
    text
    <p>I'm just starting to dive into Node.JS, and by extension JavaScript, and am having a heck of a time reading code when a parameter could be an object or function. I'm currently using IntelliJ's IDEA as my IDE, so is there a way in IDEA to independently edit the color/font for object parameters and function parameters?</p> <p><strong>EDIT: Added Example</strong></p> <p>I'm working my way through The Node Beginner Book by Manuael Kiessling (http://www.nodebeginner.org), so these examples are directly from there.</p> <p>In index.js there is an object variable <code>handle</code> that serves as an associative array of url paths to function names, such that <code>handle</code> and <code>pathname</code> become objects.</p> <pre><code>var server = require("./server"); var router = require("./router"); var requestHandlers = require("./requestHandler"); var handle = {}; handle['/'] = requestHandlers.start; handle['/start'] = requestHandlers.start; handle['/upload'] = requestHandlers.upload; server.start(router.route, handle); </code></pre> <p>In router.js there is a function <code>route</code> that serves to direct handles that have a valid pathname to their respective function and invalid pathnames to an informative 404.</p> <pre><code>function route(handle, pathname, response) { console.log("About to route a request for " + pathname); if (typeof handle[pathname] === 'function') { handle[pathname](response); } else { console.log("No request handler found for " + pathname); response.writeHead(404, {"Content-Type": "text/plain"}); respones.write("404 Not Found"); response.end(); } } exports.route = route; </code></pre> <p>In server.js there is a function <code>start</code> that uses <code>handle</code> (ala object) and <code>route</code> (ala function) as parameters to start the server. var http = require('http'); var url = require('url');</p> <pre><code>function start(route, handle) { function onRequest(request, response) { var pathname = url.parse(request.url).pathname; console.log('Request for ' + pathname + ' received.') route(handle, pathname, response) } http.createServer(onRequest).listen(8888); console.log('Server has started.'); } exports.start = start; </code></pre> <p>So, for the <code>start</code> function it would be nice to have some visual distinction between the <code>route</code> parameter, which is itself a function, and the <code>handle</code>, which is simply an object.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload