> You kidding me?  Thats way too easy! :-)

You win some, you lose some. Next time it will be browser inconsistencies!
:-)

> I was thinking usng .apply here.  But I wasn't 100% sure how 
> that worked.
> 
> In general, if I see something like this:
> 
>     xxx.apply(x,[y,z]);
> 
> >From what I am understanding, x is "this" inside the function xxx and
> x,y is the parameter to the function?
> 
> Is that correct in general when using .apply? or am I off 
> base completely? <g>

100% correct. foo.call() can also be useful in some situations - the example
above would be:

   xxx.call( x, y, z );  // === xxx.apply( x, [y,z] );

In your first example:

>      var how = (settings.show!="")?settings.show:"show";
>      eval("$box."+how+"()");

you don't really need call or apply, since you aren't doing anything special
about "this" and aren't passing any arguments into the function.

There's an interesting use of apply in some code I posted earlier today
(slightly updated from the original post):

    $.expire = function( fn, callback, interval, start ) {
        var timer;
        function set() {
            timer = setTimeout( callback, interval );
        }
        if( start ) set();
        return function() {
            clearTimeout( timer );
            set();
            return fn.apply( this, arguments );
        };
    };

$.expire takes a function (fn) and returns a replacement function which sets
a timeout and then calls the original function. In order to pass through
both the "this" value and the argument list from the original function, the
code uses:

    return fn.apply( this, arguments );

That can be useful for all sorts of things where you want to wrap an
existing function inside a new function that adds behavior before or after
the original function.

-Mike

Reply via email to