Results 1 to 3 of 3

Thread: Ultimate Fade-in slideshow: Code Question

  1. #1
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Ultimate Fade-in slideshow: Code Question

    1) Script Title: Ultimate Fade-in slideshow (v1.5)

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...nslideshow.htm

    3) Describe problem:

    I have read through the code and all of it makes sense, except I am stuck on one part. Could someone please explain the logic behind the cacheobj in fadeshow.prototype.rotateimage:

    Code:
        // If pause onMouseover enabled, cache object
        if(this.pausecheck == 1)
        {
            var cacheobj = this;
        }
    
        if(this.mouseovercheck == 1)
        {
            setTimeout(function(){cacheobj.rotateimage()}, 100);
        }
    Specifically, why create a new var cacheobj rather than simply use 'this' in setTimeout()?

  2. #2
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    okay. I think I know. It's a closure. I forgot about the context-dependent nature of 'this.' Thus, cachobj provides a concrete reference to the fadeshow instance, where 'this' does not.

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You hit the nail right on the head.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •