Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6906257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:17:12+00:00 2026-05-27T08:17:12+00:00

jQuery’s .each function takes exactly one argument- a function. And yet, In this piece

  • 0

jQuery’s .each function takes exactly one argument- a function. And yet, In this piece of jQuery code, we see the following:

if ( callback ) {
    self.each( callback, [ responseText, status, jqXHR ] );
}

Two args are being passed to .each. I’m assuming the values in brackets are params to the callback function, but I’m not clear on why this is possible and why someone would do this rather than calling the function directly? :

if ( callback ) {
    self.each( callback(responseText, status, jqXHR) );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T08:17:13+00:00Added an answer on May 27, 2026 at 8:17 am

    “I’m not clear on why this is possible and why someone would do this…”

    They wouldn’t. It’s for internal use only: https://github.com/jquery/jquery/blob/1.6.2/src/core.js#L248-253

    // Execute a callback for every element in the matched set.
    // (You can seed the arguments with an array of args, but this is
    // only used internally.)
    each: function( callback, args ) {
        return jQuery.each( this, callback, args );
    },
    

    This behavior could change at any time.


    To be clear, normally your callback to each gets two arguments:

    • the i (property name or index) of the collection as the first

    • the value of the item at i as the second

    But sometimes internally they want to use the each iterator, but they have no need for those arguments, and instead they want to substitute their own.

    That’s what’s happening. You can see here that if the internal args property has been given a value, they do a slightly different iteration of the collection passing the args that were given.

    So they do:

    callback.apply( object[ name ], args )
    

    …instead of:

    callback.call( object[ name ], name, object[ name ] )
    

    …or slightly something different but effectively the same for an Array-like collection.


    You can test it on your own:

     // normal usage
    $('p').each(function( a, b, c ) {
    
         // will show the index, the element, and undefined for each "p" element
        console.log( a, b, c ); 
    
    });
    
     // internal usage
    $('p').each(function( a, b, c ) {
    
         // will show 1, 2, 3 once for every "p" element
        console.log( a, b, c );
    
    }, [ 1, 2, 3 ] );
    

    But again, this behavior isn’t for public use, and could change without warning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

jQuery('td[class=bgoff]').each(function() { var td = jQuery(this); ... no apply selector to this only });
jQuery(document).ready(function(){ $(function() { $('.button-a').each(function() { $(this).hover( function () { $('.button-title', this).animate({ opacity: 0.6 },
Jquery Code: $(.tog).toggle( function() { $(.tog span).removeClass('stog'); $(.tog span).addClass('stogm'); $(this).next().slideDown('fast'); }, function() { $(.tog
jQuery(document).ready(function () { $lstAccountType = $('select[id*=account_type]'); $lstAccountType.change(function () { $(this).remove('option[text=select one]') }); }); I
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {
jQuery's getScript function doesn't seem to support an error callback function. I can't use
jQuery has the .ready() function, but I am unsure whether this is what I
jQuery snippet: $(.sliders dt a).click(function(){ $(this).parent().parent().parent().find(.triggers a).removeClass(active); $(this).toggleClass(active); $(this).parent().next(dd).slideToggle(fast); return false }); HTML: <div
jQuery(document).ready(function(){ var panelContainer = jQuery('div#panels'); jQuery('<div id=tabs></div>').insertBefore(panelContainer); panelContainer.find('div.panel').each(function(n){ jQuery('div#tabs').append('<a class=tab href=#' + (n+1) +
jQuery(document).ready(function ($) { $('body').keypress(function (e) { alert(e.which); }); }); This will pop up an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.