This is what I tried:
var app = function() {
var listen;
return listen = function()
{
return "ggg";
}
}
console.log("dd: " + app().listen().length);
This says listen is not a function.
console.log("dd: " + app().listen().length);
Now w.r.t socket.io, we can write:
const express = require('express');
const app = express();
app.listen();
I want to understand how to write like socket.io where from we can call one function from another?
2
Answers
you are returning an expression which returns undefined as somevar = ‘somevalue’ will give you undefined. instead you should
You seem to want to create a factory function. The problem is that you are calling it’s result as if it were an Object (with method
listen
). The way you created the functionapp
returns a (named) function. See the snippet