In FIREBUG, if an object has both the length attribute and the splice method, It will be displayed as an array by firebug.
The Code is as follows:
Var obj = {length: 0, splice: function (){}}
Console. log (obj)
Guess what is printed on it?
That's right. The output looks like an empty array...
In FIREBUG, if an object has both the length attribute and the splice method, It will be displayed as an array by firebug...
If you have noticed this before, you will find that JQUERY is written in this way. The print via selector looks the same as the array.
I have always been curious about the array returned by Mao, but there are methods that the array does not have at all, and there is no such method as the array, such as pop.
Finally, we found such an interesting phenomenon only by checking the information ..
But what is printed under IE is the normal [Object.
So you can play it like this ....
The Code is as follows:
Var push = Array. prototype. push;
Var splice = Array. prototype. splice;
Var a = function (){
Var a = function (name ){
Return new a. fn. init (name)
}
A. fn = a. prototype;
A. fn. init = function (name ){
Var arr = document. getElementsByTagName (name );
Merge (this, arr );
}
A. fn. splice = splice;
A. fn. init. prototype = a. fn;
Return;
}()
Function merge (first, second) {// completely copy the merge method in jquery --
Var I = first. length | 0, j = 0;
If (typeof second. length = "number "){
For (var l = second. length; j <l; j ++ ){
First [I ++] = second [j];
}
} Else {
While (second [j]! = Undefined ){
First [I ++] = second [j ++];
}
}
First. length = I;
Return first;
}
A.fn.css = function (pop, val ){
For (var I = 0; I <this. length; I ++ ){
If (this [I]. nodeType = 1 ){
This [I]. style [pop] = val;
}
}
Return this;
}
Var AB = a ('P ');
AB .css ('backgroundcolor', '0000444444'0000.css ('borderwidth', '2px'0000.css ('borderstyle', 'solid ')
Therefore, the mountain version of jquery only supports the tagName selector and only one library of the shanzhai CSS method is born ..