jquery - variable named undefined in Javascript Libraries -
possible duplicates:
how javascript/jquery syntax work: (function( window, undefined ) { })(window)?
what advantages using (function(window, document, undefined) { … })(window, document) confer?
i have seen many javascript libraries create variable named "undefined", iam unable figure out purpose, below lines copied jquery library
* date: wed feb 23 13:55:29 2011 -0500 */ (function( window, undefined ) { // use correct document accordingly window argument (sandbox) var document = window.document; var jquery = (function() {
please suggest me reason , benefits of doing so!!
what see this:
(function(undefined) { /* lots of code */ }());
this creates anonymous function , executes it. function has parameter called undefined
. since there no argument passed function, variable undefined
in fact javascript primitive value undefined
.
so why want this? well, problem can create variable name undefined
, set like, e.g.:
var undefined = 'some text';
a test myvalue === undefined
within code have unexpected results.
the anonymous function parameter called undefined
"resets" value of undefined
primitive value, can check against if wish without having worry whether has right value.
Comments
Post a Comment