0

Studying Module pattern in javascript and see below.. Question.. why do you need return inside of return? what purpose does that serve?

   var ex = function(){
        return {
            get: function(name){
                console.log("helloe " + name);
                return {
                    hostname: 'node1 '
                }
            }
        }
    }

1 Answer 1

2

Here you are returning an object literal.

var ex = function(){
    return {

Here you are declaring a function get inside that object literal.

get: function(name){

Here, you are returning an object literal each time the get function is called.

  return {
     hostname: 'node1 '
  }
Sign up to request clarification or add additional context in comments.

3 Comments

understand this and appreciate it but I would love to see practical reason why this is call this way? I would think it's just simple to return {get: { hostname: 'node1'} } . what is the difference between that and return { get: function(name)}; return { hostname: 'node1'}} ??
Then I need to know what module system you are talking about, It does seam like an unnecessary complexity, do you have the links you are reading?
I will accept your answer(it's detailed and broken into steps). thank you. It was from some video tutorial. thank you

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.