On Tue, Sep 15, 2009 at 1:27 AM, Andrea Giammarchi <
andrea.giammar...@gmail.com> wrote:

>
> @Michael Geary, it seems you never have to debug your code, do you? It is a
> good practice to name functions 'cause thousands of "anonymous" error are
> quite meaningless. My example is a de-facto behavior, with named functions.
>

Of course I have to debug my code! :-)

It never bothers me to have anonymous functions on the call stack, since I
can just click on them and see the the source code.

But if you like seeing function names in the call stack, you can do that *
and* write code with correct portable syntax. You simply used a named
function expression.

Here my two previous examples updated for pretty call stacks:

var slice = (function($slice){
    try {
        $slice.call(document.childNodes);
        var slice = function *slice*(list){            return
$slice.call(list);
        };
    } catch(e) {
        slice = function *slice*(){             for(var r = [], i = 0,
length = list.length; i < length; ++i)
                r[i] = list[i]
            ;
            return r;
        };
    };
    return slice;
})(Array.prototype.slice);

Or:

var slice = (function($slice){
    try {
        $slice.call(document.childNodes);
        return function *slice*(list){            return $slice.call(list);
        };
    } catch(e) {}

    return function *slice*(){         for(var r = [], i = 0, length =
list.length; i < length; ++i)
            r[i] = list[i]
        ;
        return r;
    };
})(Array.prototype.slice);

In both examples, we've added names to the various *slice* functions, but
the functions are still function expressions which are parsed the same in
all browsers.

-Mike

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jQuery Development" group.
To post to this group, send email to jquery-dev@googlegroups.com
To unsubscribe from this group, send email to 
jquery-dev+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to