JavaScript Object chain operation test code

Source: Internet
Author: User

Although jquery's use is gradually reduced (it is still used in projects, and the efficiency is high. I usually don't need it). I hope to reduce the dependence on jquery.
However, this chain operation method is really attractive (it seems that many new databases have adopted chain operations ).
The newbie is fearless, so I wrote the following: Code . It is mainly to avoid forgetting it later. Copy code The Code is as follows: window. k = function (){
Return new K. FN. INIT (arguments );
}
K. fn = K. Prototype = {
Init: function (){
This. Length = 0;
// Var ARGs = array. Prototype. Slice. Call (arguments, 0 );
Array. Prototype. Push. Apply (this, arguments [0]);
Return this;
},
Show: function (){
Console. Log (array. Prototype. Slice. Call (this, 0). Join ("$ "));
Return this;
},
Hide: function (){
Console. Log (this );
Return this;
}
}
K. FN. init. Prototype = K. FN;
Console. Log (K ("0", 1, 2, 3, 4, 5). Show (). Hide ());

This is just a chain operation. But under firbug, we can see that the returned jquery object is an array/class array. I don't know how to implement this ..

K. FN. Prototype = new array () is not allowed. Look at jquerySource codeI am a little tired ..

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.