jquery source Analysis and the principle of understanding the Extend method from the perspective of jquery object creation

Source: Internet
Author: User
Tags extend mixed xmlns
1.1 Creating plugins that belong to jquery objects

Before I saw the jquery plugin way: Through the $.extend way can define the global plug-in jquery itself, for this I did the following test, we first look at the following JS code:

;(function ($) {
    //create jquery global scope plug-in
    $.extend ({
        ' wholeftn ': function () {
            Console.log (' You want to call with the JQUERY.WHOLEFTN () method if jquery (XX) wholeftn () will error ')    
        ,
        ' wholeattr ': ' Global jquery Property '
    });
    Create a JQuery object plug-in
    $.fn.extend ({
        ' PARTFRN ': function () {
            Console.log (' You want to use jquery (XX). WHOLEFTN () mode call, If JQUERY.WHOLEFTN () will error ')    
        ,},
        ' partattr ': ' Local jquery scope '
    })
(JQuery)

The test code is as follows:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">  

We found that $.extend is the method and property of creating a global jquery object, much like a static and static variable in Java, and a method of using $.fn.extend to create a jquery (XX) object. There is a difference between the two: the difference is that one belongs to the global and one belongs to the object. The $.ajax we often use is the global approach and $ (' div '). html () is the method that belongs to the jquery object, let's take a closer look at the jquery Handbook, Almost all of the properties and methods of jquery can be categorized according to the jquery Global and belong to the jquery object, so I have a view:

To understand the principle of the jquery framework, read its source code, plug-in technology is a good point of entry, the entire jquery framework is divided into three parts: the first part is how to build a jquery object, the second part is how to create a jquery global properties and methods, The third part is how to create the properties and methods belonging to the JQuery object, and the first part is the basic of the jquery framework, the latter two parts is the extension of the jquery framework, as long as the first part of understanding, including how to build jquery Global plug-ins and jquery object plug-ins we can really understand the principles of jquery framework Design

I'll take a good look at how the jquery framework builds on jquery objects. How to define jquery objects in the 1.2 jquery framework

The jquery object is defined using JavaScript's most basic technology: object creation and object inheritance, and the point is to create a JavaScript object and use the prototype technology in JavaScript, and look at the following code:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 

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.