Maybe more a Javascript question than a Express question

41 views
Skip to first unread message

Victor Zambrano

unread,
Jun 21, 2016, 2:39:10 AM6/21/16
to Express
First of all, I am very new to this Javascript thing, so maybe my question is yielded by my ignorance.

router.get('/', function(req, res) {
  res
.send('Hello World');
});

As far i understand, the get method return some parameters (req, res, next) to the anonymous function.

How do i know what is passed back (maybe more parameters like next() for example) ? I reviewed the API and could not find something related.

I am having the same issue with other Node modules. Parameters going back to anonymous functions everywhere. What am I missing in my journye to Javascript ?

Thank you very much.

hacksparrow

unread,
Jun 21, 2016, 2:46:41 AM6/21/16
to Express
There is an object named arguments inside every function, which contains all the parameters that were passed to the function. You can do console.log(arguments) to see what they are. Beware though, the arguments object looks like an Array, but it is not; it is an Array-like Object. 

Paul Vencill

unread,
Jun 21, 2016, 7:45:57 AM6/21/16
to expre...@googlegroups.com

Sort of.

To be precise, the 'get' method in this case is being invoked with two parameters, a string (the web request path pattern to match), and a callback function (the code that should be executed when a request matches the pattern).

When the callback is called, the calling code (in this case, the get method provided by express) supplies whatever parameter signature it wants, which we discover by documentation or by logging the arguments object if the module writer wasn't so great at documentation.

Frequently callbacks have a signature of function(errorObject, resultObject), with on or the other being null depending on error condition. A lot of those go undocumented by module writers in my experience because they assume folk know the convention.

--
You received this message because you are subscribed to the Google Groups "Express" group.
To unsubscribe from this group and stop receiving emails from it, send an email to express-js+...@googlegroups.com.
To post to this group, send email to expre...@googlegroups.com.
Visit this group at https://groups.google.com/group/express-js.
For more options, visit https://groups.google.com/d/optout.

Victor Zambrano

unread,
Jun 21, 2016, 10:40:06 AM6/21/16
to Express
Great response from all of you guys, thank you  very much, know i am maybe able to make a step forward.
Reply all
Reply to author
Forward
0 new messages