I am trying to understand the below snippet of code in javascript. I have tried to google to check the usage of creating javascript function in the below format, but i did not find any references.
Below is the my understanding of the code and plz correct if this is what the code and appreciate any reference Guide to check more on this type of using notation.
function(obj)
--> this is basically running a function in the global scope which is run on the load of the page after the DOM is loaded.obj['test'] = 'DummyObj';
This is creating a global variable. I guess i am sure on this usage.obj['test1'] = obj['test1'] || function(){ (obj['test1'].h = obj['test1'].h||[]).push(arguments) }, obj['test1'].m = 1 * new Date()
I am having trouble in understanding this. My analysis is this is checking for if test1 object is null it is creating a function and in that function it is checking for 'h' object and if it is null it is creating an Empty Array and pushing the local 'arguments' Object. I don't understand the second part where we have a comma and date object is created? Does it mean that it would execute as one statement and create a 'm' local variable with current Date value?- The last part where we are using (window) is what i don't understand completely. What does it mean? Can you please guide me where to further read on this
(function(obj) {
obj['test'] = 'DummyObj';
obj['test1'] = obj['test1'] || function(){
(obj['test1'].h = obj['test1'].h||[]).push(arguments)
},
obj['test1'].m = 1 * new Date();
})(window);