Lal Rishav
Lal Rishav

Reputation: 11

Exporting a function inside a function

app.js

var a = function(){
      var b = function(){
          console.log("hello")
      }
}

module.exports = {a}

index.js

console.log(require("./app.js").a().b())

I wantr to get the output "hello" but i am getting error can call property b of undefined Please help to obtain the result

Upvotes: 1

Views: 31

Answers (1)

Rahul Sharma
Rahul Sharma

Reputation: 10071

try this

var a = function () {
    var b = function () {
        console.log("hello")
    }
    return {b:b};
}

Upvotes: 3

Related Questions