Why do people call the jQuery $ alias a 'factory'?

前端 未结 2 709
不思量自难忘°
不思量自难忘° 2021-01-11 20:16

On various sites, jQuery\'s $ variable is referred to as an alias, and on others, it is referred to as a factory. I took a look at the source code, and I think

2条回答
  •  耶瑟儿~
    2021-01-11 20:24

    The jQuery function (on the right of the assignment in your question) is a factory (it creates new jQuery objects). It is not in the global scope, because it is defined in the scope of a self-executing function.

    window.$ and window.jQuery are global aliases for the constructor.

提交回复
热议问题