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