开发者

JavaScript function with 'undefined' parameter [duplicate]

开发者 https://www.devze.com 2023-02-04 13:00 出处:网络
This question already has answers here: What advantages does using (function(window, document, undefined) { ... })(window, document) confer? [duplicate]
This question already has answers here: What advantages does using (function(window, document, undefined) { ... })(window, document) confer? [duplicate] (4 answers) Closed 7 years ago.

Going around Modernizr source code I have found strange thing:

windo开发者_高级运维w.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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号