Implementation of each

Source: Internet
Author: User

Function (object, callback, argS ){
// This method has three parameters: Object OBJ for operation, FN for operation, and ARGs for function parameter
VaR name, I = 0, length = object. length;
If (ARGs ){
If (length = undefined ){
For (name in object)
{
If (callback. Apply (object [name], argS) === false)
{
Break;
}
}
}
Else
{
For (; I <length ;)
{
If (callback. Apply (object [I ++], argS) === false)
{
Break;
}
}
}
}
Else
{
If (length = undefined ){
For (name in object ){
If (callback. Call (object [name], name, object [name]) === false ){
Break;
}
}
}
Else
{
For (VaR value = object [0]; I <length & callback. Call (value, I, value )! = False; value = object [++ I]) {}
/* Object [0] gets the first Dom element in the jquery object through the for loop,
Get each Dom element corresponding to the entire jquery object and Use callback. Call (value, I, value );
Point this object of callback to the value object and pass two parameters. I indicates the index value and value indicates the DOM element;
Callback is similar to function (index, ELEM.
So we get $ ("..."). Each (function (index, ELEM ){...});
*/
}
}
Return object;
}

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.