JQuery. noConflict () _ jquery-js tutorials

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.