It's late in the evening here so I may not be functioning very well, but I found this piece of code and I can't seem to figure out why it's used like this (NOTE: I understand what it does, what I don't understand is the meaning behind it).
(function() {
var narcissus = {
options: {
version: 185,
},
hostGlobal: this
};
Narcissus = narcissus;
})();
Self-executing anonymous functions are used to avoid pollution of the global namespace, but this code doesn't need to introduce other variables than Narcissus
so it could have very easily be rewritten as Narcissus = {...};
. Some possible reasons I can think of are future-proofing of the code or implementation flaw. Is there something I fail to see?
A line of code (LOC) is any line of text in a code that is not a comment or blank line, and also header lines, in any case of the number of statements or fragments of statements on the line. LOC clearly consists of all lines containing the declaration of any variable, and executable and non-executable statements.
In this article, we define a piece of code by using the code Element. It is used to define the piece of computer code. During the creation of web pages, sometimes there is a need to display computer programming code.
While the names of the coding paradigms sometimes vary, most experts agree on four primary types of code: imperative, functional, logical, and object-oriented.
From a maintainability standpoint it allows the author to later add code in a Closure scope that doesn't get leaked between the creation of narcissus
and the assignment of Narcissus
. Though in this case there isn't any code there so I don't see any gains other than the this
stuff mentioned above.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With