Hanqing Zhao
Hanqing Zhao

Reputation: 25

do not understand the query string parse with function and parameter

I do not understand such snippet of code. is there any master can help me explain that: I already search the explanation of querystring.parse(str, [sep], [eq], [options]). However, I do not understand why there is a "= function (str){}" after it. thanks Here is the code:

(function () 
 {
    'use strict';
    var queryString = {};
	
    queryString.parse = function (str) //do not know why there is a function assigned here
	{
        if (typeof str !== 'string') 
		    {
            return {};
        }

        str = str.trim().replace(/^\?/, '');

        if (!str) {
            return {};
        }
  }
});

Upvotes: 0

Views: 392

Answers (1)

Typhlow
Typhlow

Reputation: 15

It's just saying that it is a function and it will run the code inside the curly brackets when called. In this case queryString is not the node module, since it was not required and assignet to that value(like one would with const querystring = require('querystring')), instead it is just an empty object (as you can see in var queryString = {})

Upvotes: 1

Related Questions