javascript - Why is Router used like normal function instead of constructor in express 4.x? -


i newbie trying understand express 4.x routing , reading guide at: http://expressjs.com/guide/routing.html

in last paragraph says following:

the express.router class can used create modular mountable route handlers. router instance complete middleware , routing system

and accompanying code is:

var express = require('express'); var router = express.router(); 

why express.router constructor called ordinary function without new operator? in documentation it's class, named according javascript style (capital first letter) (and other examples online) use ordinary function.

some people support functional style in addition traditional instantiation. done adding simple check @ top of function:

function router() {   if (!(this instanceof router))     return new router();    // ... } 

this allows support of both types of invocations (with new , without).


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -