Proxy

# Uther Pendragon (8 years ago)

Perhaps it's a bit late... but I'd like to discuss the proxy object. Notably: why no way to define a hook for when a property is called as a function.

I think I understand why there isn't one.. I presume because how a property is used (I.e. as a property or called as a function) is a level deeper than the recalling of said property. If at all possible, I think it would be incredibly useful. This may be outside the intended purpose of the proxy object, but a proxy for the purposes of a middleware (I hate that word too) that is more dynamic would be perfect for adaptors etc... Perhaps it's not feasible, because the proxy hook is best applied at the point when the property's definition, which brings me to my next suggestion....

What about the ability to alter / define the configuration of a scope variable, like those on objects with defineProperty... but with simple scope variables... I presume most implementations define scope variables much like object properties internally.

On Dec 14, 2016 2:56 PM, <es-discuss-request at mozilla.org> wrote:

Send es-discuss mailing list submissions to es-discuss at mozilla.org

To subscribe or unsubscribe via the World Wide Web, visit mail.mozilla.org/listinfo/es-discuss or, via email, send a message with subject or body 'help' to es-discuss-request at mozilla.org

You can reach the person managing the list at es-discuss-owner at mozilla.org

When replying, please edit your Subject line so it is more specific than "Re: Contents of es-discuss digest..."

Today's Topics:

  1. Re: Ranges (Jeremy Martin)
  2. Re: Ranges (Alexander Jones)
  3. Re: Destructuring object outside of var declaration (Jeff Walden)

---------- Forwarded message ---------- From: Jeremy Martin <jmar777 at gmail.com>

To: Hikaru Nakashima <oao.hikaru.oao at gmail.com>

Cc: es-discuss <es-discuss at mozilla.org>

Date: Wed, 14 Dec 2016 11:55:02 -0500 Subject: Re: Ranges While slightly more verbose, the previously suggested ... syntax does have a superficial consistency with the spread operator. Both perform an expansion of sorts, which has a subtle elegance to it, IMO.

# Boris Zbarsky (8 years ago)

On 12/14/16 8:47 PM, Uther Pendragon wrote:

Perhaps it's a bit late... but I'd like to discuss the proxy object. Notably: why no way to define a hook for when a property is called as a function.

See thread at esdiscuss.org/topic/es6-proxy-function-call-trap.

I think I understand why there isn't one.. I presume because how a property is used (I.e. as a property or called as a function) is a level deeper than the recalling of said property. If at all possible, I think it would be incredibly useful.

It's possible, in general; it was there in the proxy proposals at some point, as the thread linked above says. It leads to weird consequences like "foo.bar()" behaving differently from "foo.bar.call(foo)" when everyone expects them to be the same thing.

I presume most implementations define scope variables much like object properties internally.

That's not clear to me at all. In general, non-object environments don't need to support all the operations objects do (e.g. you can't delete bindings), so the implementation tradeoffs are quite different and using a separate codepath for environments and object properties is likely to be appropriate. Certainly the one implementation for which I know this details (SpiderMonkey) has quite different implementations for scope variables and object properties.

# Andreas Rossberg (8 years ago)

On 15 December 2016 at 03:26, Boris Zbarsky <bzbarsky at mit.edu> wrote:

I presume most implementations define scope

variables much like object properties internally.

That's not clear to me at all. In general, non-object environments don't need to support all the operations objects do (e.g. you can't delete bindings), so the implementation tradeoffs are quite different and using a separate codepath for environments and object properties is likely to be appropriate. Certainly the one implementation for which I know this details (SpiderMonkey) has quite different implementations for scope variables and object properties.

Indeed, the two couldn't be more different. In general, there isn't even a self-contained data structure representing a scope, let alone a unique one. Some variables might live in registers, some on the stack, some on the heap, some in several of those places at different points in time, some are optimised away entirely. Their names are not generally kept around either.

# Isiah Meadows (8 years ago)

You can always just return a callable from handler.get. Function closures are much more ergonomic than proxies for that in my experience, although I generally make no distinction regarding this (which only complicates in this area).

# Uther Pendragon (8 years ago)

Agreed, but it lacks intent... I.e., the get handler doesn't know whether the return value is being called.

Imagine a layer that is so robust and flexible that, to use it, you don't have to know or care how the things are used... You just do what makes sense and it works... this concept kinda depends on knowing whether something is being called from, read or assigned when the handler is called.