Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript How to interrupt an immediately-invoked function?

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #198745
    Shikkediel
    Participant

    Lately I’ve been reading up on how to make your own jQuery plugins and tried out some things that worked alright. One of those is this :

    http://codepen.io/Shikkediel/pen/xbRaZz

    My question is – how to detect if this function is busy when it is triggered again? For example when I try to bind it to a mouseenter event. At the moment it will either start over or flickering, which makes me assume the function runs parallel to itself.

    The problem could so far be boiled down to the fact that this type of function has no global scope, all it’s variables are private. So how can I interact with it when it’s running?

    Any guide points would be much appreciated, of course I’ll google and read more on the subject meanwhile.

    #198752
    Shikkediel
    Participant

    Thinking about it, I reckon jQuery itself has a different approach – queuing the function and applying a different extension (stop() or finish()) for the interruption part. Much to google still when you want to reinvent the wheel, lol.

    #198771
    Shikkediel
    Participant

    Pretty sure this holds the answer :

    http://stackoverflow.com/questions/1149274/extend-a-jquery-plugin

    Good advice is always welcome of course.

    #198783
    Shikkediel
    Participant

    Found a workaround (see the pen) – building in a mouseleave option into the function itself. Animation is now interrupted when not hovering.

    Much to read up on still though. Variable scope is a tricky one.

    #198807
    Shikkediel
    Participant

    A bit circumventive and not quite what it may end up to be but not too shabby nonetheless, I think. Hovering should work properly now. Anyway, could someone maybe check for me if it works on Safari? Coded some touch events into it as well (but not sure the prefix works).

Viewing 5 posts - 1 through 5 (of 5 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.