On Sat, Dec 12, 2009 at 10:53 AM, Mike Samuel <[email protected]> wrote:
> On the interaction of Function.prototype.toString and function
> proxies, one use case is code that tries to get at a function's name
> as by doing
>
> function nameOf(f) {
> if ('name' in f) { return f.name; } // Works on some interpreters
> var m = ('' + f).match(/^function\s+([^(\s]+)/);
> return m ? m[1] : void 0;
> }
>
> I'm not sure how much of the existing code like this invokes toString
> directly or indirectly instead of using Function.prototype.toString.
>
> Function proxy handlers could implement has('name') then there might
> not be a need for Function.prototype.toString to support this use
> case.
>
>
Under the current proposal, a trapping function proxy f can virtualize all
the following without problem:
'name' in f
f.name
'' + f
f.toString()
The only open issue is
Function.prototype.toString.call(f)
I would have ventured a guess that this isn't used in real code. But having
learned my lesson ;), I looked. What do we all think of <
http://www.google.com/codesearch?hl=en&lr=&q=Function.prototype.toString.call+lang:javascript&sbtn=Search
>?
--
Cheers,
--MarkM
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss