Hacker News new | past | comments | ask | show | jobs | submit login

Add a "displayName" property to anonymous Javascript functions, then hack the WebKit debugger to show that in the profiler and debugger. Simple, yet brilliant.

There's a lesson here in seeing a problem and solving it instead of complaining about it. I had heard recently about the problem with FireBug (for example) not having a name to show for anonymous functions, but I considered it an annoyance to be coped with, rather than a bug to fix.

Also a big win for open source. This process is not possible with IE.




> This process is not possible with IE.

It seems like the IE developers already implemented a trick similar to this last year: http://blogs.msdn.com/ie/archive/2008/09/11/introducing-the-.... For all we know, this WebKit improvement is inspired by the IE8 profiler. Accordingly, this is a bad case to use as an example of the alleged benefits of open source over closed source software since the closed source implementation came first and costs no more than the open source version.


Actually, it's not really the specific enhancement that makes it a good example of the power of open source, but the fact that this is possible at all. It's not as if there aren't plenty of other features that could be added using this same process that IE doesn't already have.


    In some cases, this might fail to infer a name, 
    in which case, the function is listed with 
    the special name “[Anonymous]”.
IE suffers from the same problem the other profilers do. They may "try" to be smart, but there's no substitute for actually letting framework authors provide the most accurate information they can.


It looks like the IE version is a bit more clever, since it seems to grab the name of the function at the point it's first bound to a variable. Huge benefit being you don't have to go back an instrument your code with .displayName's everywhere.


Both Safari and Firebug employ similar "tricks" to try to infer the name. The point is that none of them is fool proof (especially in cases of generated functions), and its nice to have something to fall back on when you run into this problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: