I have a clarification in using Immediately Invoked functions (IIFs) in JavaScript. I have downloaded a JavaScript file called called test.js as follows and I have got following questions after Googling IIFs:
define(function () { (function (window) { this.test = function() {}; Test.prototype.function1 = function(){ //Do something }, function Delete(){ //Code to Delete } window.Delete = Delete; })(window); }); I do have the following questions:
Is the line,
this.test = function() {};a constructor? If so can I have 2 constructors in a single file like for example:this.test = function() {}; this.test2 = function() {};And also, why would I need a constructor when I know that this is an automatically invoked file where everything gets executed initially itself.
Is this a private function?
Test.prototype.function1 = function(){ //Do something },Does this not get automatically? Should I need to create an object of the test and then invoke it?
Is this a public function?
function Delete(){ //Code to Delete } window.Delete = Delete;The last line of the above says that . If it is so then whats the difference between first and second function?
What is keyword
windowhere?
})(window);