Tuesday, 14 March 2017

Using dot operator with functions

I have just started learning javascript and nodejs by following a tutorial. One of the code they used is:

var express=require('express');
var app=express();
app.listen(3000);

Now when I do:

console.log(typeof app);
console.log(typeof app.listen);

I get:

function
function

as the output. Now if the typeof app is function, then how can we use . operator with it to access some other function(listen)? I tried to read the express module but couldn't understand much.

Can anyone give a simple example where we use a function name with . operator to access some other function inside it?

I tried this:

var t=function(){
    t.bar=function(){
        console.log('bar');
        }
    };  

t.bar();

But doesn't work.



via shiva

No comments:

Post a Comment