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 ">