Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript function with 'undefined' parameter [duplicate]

Tags:

Going around Modernizr source code I have found strange thing:

window.Modernizr = (function(window,document,undefined) {

After that this function will be called with two arguments (this, this.document).

Why undefined is used here? Is it meaningful or it's just strange code-style?

like image 720
Gleb M Borisov Avatar asked Jan 10 '11 19:01

Gleb M Borisov


1 Answers

Creates a local undefined in case someone redefines undefined somewhere in the scope chain.

Also provides a faster lookup since undefined is a global property, so the scope chain traversal is reduced.

like image 178
user113716 Avatar answered Sep 30 '22 18:09

user113716