1

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

1 Answer 1

3

try this

var a = function () {
    var b = function () {
        console.log("hello")
    }
    return {b:b};
}
Sign up to request clarification or add additional context in comments.

1 Comment

thanx u save my day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.