An interesting description of firebug _ javascript skills

Source: Internet
Author: User
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 ..
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.