user3502374
user3502374

Reputation: 779

javascript module pattern returning return?

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 '
                }
            }
        }
    }

Upvotes: 0

Views: 24

Answers (1)

Alexandre Borela
Alexandre Borela

Reputation: 1626

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 '
  }

Upvotes: 2

Related Questions