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

  • SEARCH
  • Home
  • 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 4332284
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T10:14:04+00:00 2026-05-21T10:14:04+00:00

I’m working through R Murphy’s JQuery Fundamentals and am trying to make sense of

  • 0

I’m working through R Murphy’s JQuery Fundamentals and am trying to make sense of her solution: slideshow.js.

She’s created the following function (I’ve removed some of the navigation code in order to focus on the core functionality of fading images in and out):

fadeCallback = function() {
            if (manualMode) { return; }

            var $this = $(this),
                $next = getItem($this, 'next'),
                num = $this.prevAll().length + 1;

            // set the timeout for showing
            // the next item in 5 seconds
            timeout = setTimeout(function() {
                showItem($this, $next);
            }, 5000);
        };

Inside fadeCallback she calls getItem() to get the next sibling of $this:

getItem = function($item, trav) {
            var $returnItem = $item[trav]();
            return $returnItem.length ? 
                $returnItem : 
                $items[(trav == 'next') ? 'first' : 'last']();
        },

I’m getting lost by her use of ‘next’ in the second argument to getItem(). Is this a roundabout way of calling the .next() jQuery function on the first argument, ‘$(this)’?

If so, why not just call the function directly? i.e. $item.next();?

Follow-up question

Maybe I’ve been looking at this code too long but it seems to me that inside getItem(), in the line:

$items[(trav == 'next') ? 'first' : 'last']();

trav is never not ‘next’. Yet by virtue of the code testing whether trav equals ‘next’ it implies that there are cases where trav != ‘next’. But I can’t identify any such case.

What am I not seeing?

  • 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-21T10:14:05+00:00Added an answer on May 21, 2026 at 10:14 am

    The code needs to make a decision whether to call the “first” or “last” function, based on whether the value of the parameter is the string “next” or not. Thus, it performs the comparison, uses the result to decide between the two function names, then access the functions as properties of the “$item” object, and finally calls whichever function was chosen.

    The [ ] “operator” in JavaScript is not just for arrays. In general, it’s used to access a property of an object:

    object [ propertyName ]
    

    evaluates “propertyName” — which can be any expression — as a string, and then returns the value of the property (or undefined). If the object is an array, integer values of “propertyName” are treated slightly specially, but that treatment is subtle and pretty much undetectable because numeric properties always can work, since they have a clear conversion to string values.

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

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.