JQuery is easy to handle. noConflict (), jQuery. the implementation principles behind noConflict () are worth learning and understanding by Web developers. If you are interested, you can refer to jQuery as one of the most widely used front-end frameworks, there are a large number of third-party libraries and plug-ins developed based on it. To avoid global namespace pollution, jQuery provides the jQuery. noConflict () method to resolve variable conflicts. This method is undoubtedly very effective. Unfortunately, jQuery's official documentation does not clearly describe this method, and many developers do not know when they call jQuery. what happened when noConflict () occurs, resulting in many problems during use. Despite this, the implementation principle behind jQuery. noConflict () is still worth learning by Web developers and becomes a powerful tool to solve problems similar to global namespace pollution.
What is the role of jQuery. noConflict?
JQuery. noConflict () has only one purpose: it allows you to load multiple jQuery instances on the same page, especially different versions of jQuery. You may wonder why you need to load/use multiple jQuery objects of different versions on a page? Generally, there are two cases. First, your business code uses the latest jQuery library, and the third-party plug-ins you choose depend on earlier jQuery libraries. Second, you are maintaining a system, its Existing Business Code references older jQuery libraries for various reasons. Your newly developed modules use jQuery libraries of other versions. In either case, you have to deal with jQuery object/method conflicts. Fortunately, jQuery. noConflict () helps you solve this problem.
What happens when jQuery is loaded?
When jQuery is referenced/loaded by pages, it is encapsulated in an self-executed function (anonymous function, all the variables, functions, and objects it provides are in the executable environment of anonymous functions, and the external environment cannot be called to prevent global namespace pollution.