Monday, 26 August 2013

What are the differences between following two javascript code?

What are the differences between following two javascript code?

In some Javascript codes which uses immediate function, it has argument
window or document like the following:
(function (window, document) {
...
)(window, document);
However, window and document are global objects and can be directly
accessed as follow:
(function () {
var userAgent = window.navigator.userAgent;
...
var el = document.getElementById(...)
...
})();
What are the differences between the above two codes. Which is better way
and why?

No comments:

Post a Comment