Catch-all proposal based on proxies

Mark S. Miller erights at google.com
Sat Dec 12 11:08:33 PST 2009


On Sat, Dec 12, 2009 at 10:53 AM, Mike Samuel <mikesamuel at gmail.com> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20091212/da69a633/attachment.html>


More information about the es-discuss mailing list