For ease of writing, jQuery registers on $. In order not to conflict with other frameworks, he first backed up $ to _ $. // Mapoverthe $ incaseofoverwriteif ($) jQuery. _ $; // MapthejQuerynamespacetothe & amp; #39;... SyntaxHighli
For ease of writing, jQuery registers on $. In order not to conflict with other frameworks, he first backed up $ to _ $.
// Map over the $ in case of overwrite
If ($)
JQuery. _ $ = $;
// Map the jQuery namespace to the '$' one
Var $ = jQuery;
The following is the jQuery prototype method.
JQuery. fn = jQuery. prototype = {
Jquery: "$ Rev. 509 $ ";,
Size: function (){
Return this. length;
},
Get: function (num ){
// Watch for when an array (of elements) is passed in
If (num & num. constructor = Array ){
// Use a tricky hack to make the jQuery object
// Look and feel like an array
This. length = 0;
[]. Push. apply (this, num );
Return this;
} Else
Return num = undefined?
// Return a 'clean' array
JQuery. map (this, function (a) {return }):
// Return just the object
This [num];
},
Jquey: indicates the version number. It also indicates whether an object is jquery or not.
Size: returns the size of a jQuery object. A jQuery object is an array-like object with a length value. It can index subscripts, but there is no array method.
Get: The get method is flexible and the parameters are optional. If no parameter is specified, a jQuery object array is returned. If the num parameter is set to the numeric type, the num element is returned. If the num parameter is set to the array type, the element of the num type is set to the jQuery object element.
The highlights of the Code are
This. length = 0;
[]. Push. apply (this, num );
This indicates the jQuery instance object. Set the attribute length to 0 and press the element in num in the push method.
These two statements are indispensable. After processing is completed, it is an array object of the class, which has the length attribute and can be iterated, but there is no array method.
It is equivalent to the following code:
Var obj = new Object ();
Obj. length = 0;
[]. Push. apply (obj, [1, 2, 3]);
Alert (obj. length); // 3
Author: baozhifei