I returned an object because I wanted to send back all of the variables. A function can only return once, as soon as it has returned something it exits, even if there’s more code further down.
So I could just return each variable by itself. I could have also done it with an array, but I prefer the object notation of
object.item, it’s just more clear to me.
This line gets whatever is returned inside the function and sets it equal to a variable:
var slides = getSlides();. Now, that variable is equal to everything in the
return statement of that function. Since that’s the case,
var slides is the object.
If you were to put in code that said
console.log(slides); after it was declared, you’d see it in the console of the browser (in dev tools). Maybe that would be good so you can visualize it.
.next() are jQuery methods. They look for the next/previous sibling in the DOM. If one isn’t found, it will have a
.length of 0, not the variable itself – it’s still a jQuery object at that point.
Your last question is partially correct. If you’re on the first slide,
slides.nextSlide is set to the first
$('slide') jQuery object, not just 1 or 4. If you set something to a jQuery object, then you can manipulate it with jQuery in many ways.
Read up on tree traversal in jQuery: http://api.jquery.com/category/traversing/tree-traversal/
Don’t worry about pestering me or any of us, we love to help those that genuinely want it.