Hi, WebKit added support for this a while ago with func.displayName that usually has the same value as func.name but is writable. Here is some info on it: http://www.alertdebugging.com/2009/04/29/building-a-better-javascript-profiler-with-webkit/
This feature is extremely useful for frameworks like class builders, etc. that could do things like "ClassName$functionName" or event subscriptions where the handlers are by default named after the event topic. Cheers Malte On Aug 2, 4:34 am, Luke Maurer <[email protected]> wrote: > But you have to call thefunctionthe same thing every time. What Red > wants to do is call it something different depending on the arguments. > > The best solution I know of is to use an eval to wrap thefunction: > > functionrename(f,name) { > return eval('(function' +name+ '() { return f.apply(this, > arguments); })'); > > } > > functioncompose(f, g,name) { > return rename(function() { > return f(g.apply(this, arguments)); > },name); > > } > > Evals are ugly, though, even when relatively isolated like this. But > it does work. > > - Luke > > On Jul 29, 7:50 pm, Nicolas Hatier <[email protected]> wrote: > > > You can use this syntax: > > >functioncompose (fn1, fn2) { > > // returns afunctionthat calls fn1 with the result of fn2 > > functioninner() { > > return fn1( fn2.apply(null, arguments)) > > } > > > return inner; > > > } > > > This is perfectly valid javascript and will do exactly what you want, while > > providing anamefor the innerfunction. > > > Regards > > NH > > > reddaly wrote: > > > > On Jul 28, 3:09 pm, johnjbarton <[email protected]> wrote: > > > >> On Jul 28, 2:23 pm, reddaly <[email protected]> wrote: > > >> ... > > > >>>> Nevertheless I am interested in any incremental suggestions about > > >>>>functionnames. > > > >>> My suggestion is to inspect thefunctionobject for an explicit, user- > > >>> definedname. > > > >> I've heard this suggestion before, I didn't understand it. If you > > >> don't want anonymous functions, why don't you justnamethem? I mean > > >> aren'tfunctionnames are exactly equal to explicit user-defined > > >> names? > > > > You suggest using a form like > > > >functionmyName() { ...} > > > > instead of > > > > var x =function() { ...} > > > > x.firebugName = "myName" > > > > However, this does not always work out. Consider the case where a > > >functionreturns anotherfunction. > > > >functioncompose (fn1, fn2) { > > > // returns afunctionthat calls fn1 with the result of fn2 > > > returnfunction() { return fn1( fn2.apply(null, arguments)) } > > > } > > > > Here, there is no sensible way tonamethe composedfunction(other > > > than "composedfunction," which does not give any context about the > > > functions it comprises). Ideally, you would like tonameit something > > > recognizable. e.g. compose(tagName, firstTag) would be named > > > "tagName_firstTag." The way to accomplish this best is to set a > > > property on thefunctionthat firebug will inspect. > > > > Best regards, > > > Red > > > >> jjb --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Firebug" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/firebug?hl=en -~----------~----~----~----~------~----~------~--~---
