当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Why does jQuery pass the window object into their scope

问题描述:

This question already has an answer here:

  • What advantages does using (function(window, document, undefined) { … })(window, document) confer? [duplicate]

    4 answers

网友答案:

Yes! Since the window in this function is a local variable now it allows minify its name. Also access to the local variables should be faster than to the global ones.

网友答案:

You can access faster to local vars, also you can shorten the variable name "window" (and even "document") with something like:

(function(w, d)(){

    // use w and d var

})(window, document)
分享给朋友:
您可能感兴趣的文章:
随机阅读: