Global variables in the Javascript framework

Source: Internet
Author: User
Tags mootools

Looking at the implementation of various major types of libraries, a global variable is basically defined at the beginning and then extended. For example, Prototype. js Prototype, Native of mootools, Base of Base2, Ext of Ext, JQuery of JQuery, YUI of YUI, dojo of dojo, MochiKit of MochiKit, etc. Global variables are classified into two categories: Prototype, mootools, and Base2. The Prototype philosophy is to expand the JS native object. In earlier years, Ptototype almost became a de facto standard, so the coexistence with other libraries was hardly considered. Based on Prototype, great class libraries, such as script. aculo. us, rico, Plotr, ProtoChart, and Scripty2, and a large number of paid plug-ins have also been developed. They are not comparable to JQuery's many junk plug-ins. However, some plug-ins are almost related to Prototype, such as the famous lightbox. Mootools is an upgraded version of Prototype, which is more OO and fully copies its APIs. Base is to fix the Bug of IE, so that IE has a standard browser API, so it also contaminated all native objects.

The remaining several major types of databases adhere to the non-intrusive principle and minimize global variables. For example, Ext has more small class libraries. It selects a custom object (which is actually a custom attribute of window) and expands its attributes. The basic idea is:

Copy to ClipboardReference: [www.bkjia.com] Ext = {};. ext. element = function (){}. ext. domQuery = function (){}. ext. domHelper = function (){}

JQuery is also a window custom attribute, and contaminated two (JQurey and $) from the very beginning, so once other class libraries occupy $, it will return to JQuery. The biggest difference between it and Ext is that. It is a Function Object rather than a pure Object ). All its extensions are based on its JQuery. fn, that is, JQuery. prototype. Other variables that may be exposed receive closures and functions.

As soon as dojo comes up, it is built with no quasi-incomparable package mechanism. The entire namespace is generated by eval and then added to the dojo, in the same case as Ext. However, it is designed to be the most complex class libraries I have ever seen and involves a wide range of fields, with hundreds of thousands of lines of code (and comments ).

MochiKit does not know whether it is derived from dojo. I have not studied it much. However, its organization is similar to Ext and dojo.

YUI is similar to JQuery. It is a function object, but it is not as crazy as JQuery. Everything is added to the prototype. Undoubtedly, YUI and JQuery have a very novel concept. functions are more fun than objects, and at least chain operations are easy. But JQuery aimed at the DOM element of the page from the very beginning, and YUI, dojo, Ptototype, and mootools had a powerful Inheritance Mechanism and would like to create a class, this is why JQuery cannot match its predecessors in the UI. In addition, the authors of YUI are also very knowledgeable about CSS and HTML, so their uidesign is very worth learning.

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.