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

 
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, its design is the most complex class library I have ever seen and involves a wide range of fields.CodeMillion lines (with 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.