Catch-all proposal based on proxies

Mike Samuel mikesamuel at
Wed Dec 9 14:06:57 PST 2009

2009/12/9 Tom Van Cutsem <tomvc at>:
> On Wed, Dec 9, 2009 at 1:02 AM, Mike Wilson <mikewse at> wrote:
>> Looking at the Use Cases section in your proposal it seems most
>> of your suggested use cases would be interesting to apply on an
>> object prototype/class level when targeting many objects, to
>> avoid having to recreate the catch-all for every object and also
>> possibly adding dynamically generated methods in a common place
>> (like in Ruby/ActiveRecord).
>> Hearing that you are not certain that this is indeed an important
>> use case, or maybe use case property, I wonder if I am missing
>> something? I have full respect for that you have thought this
>> through, so maybe there is something in the language or in other
>> Harmony plans that make this less interesting?
> Ok, we should probably have made clear the distinction between our
> *motivating* use cases and other possible use cases.
> Our motivating use case for the proxy proposal is near-complete object
> virtualization, that is: the ability to emulate as much aspects of an
> object's behavior as practically possible (I'm not claiming our current
> proposal achieves full virtualization, but it comes close, given the legacy
> compatibility and security constraints).
> In this light, the "__doesNotUnderstand__" trap provides a strict subset of
> what you can do with full object virtualization. So, while you can
> definitely use the proposed proxies to build a Ruby/ActiveRecord-style
> framework in Javascript (see below), this use case was not our main
> motivation. A motivating example would be using proxies to virtualize an
> existing Javascript API (e.g. to enforce access control to the DOM, or to
> provide a legacy interface adaptor to a new API).

I.e. this allows implementing Mozilla style wrappers in user-space.
With the exception that mozilla's wrappers support ===, but by
combining this with a weak reference table mapping wrapped objects to
wrappers, you could preserve EQ as far as a piece of code that never
gets a handle to a wrapped DOM node is concerned.

>> This sounds interesting. It would be great if you could show a
>> code example? A good "demo" case could be mimicing the single
>> point catch-all and dynamic .find_by_* method generation for all
>> User objects in the ActiveRecord examples:
>> (section "Dynamic attribute-based finders")
> Here's the essence of one possible solution:
> var attributeBasedFinder = Proxy.create({
>   get: function(rcvr, p) {
>     var res = p.match(/^find_by_(.*)$/);
>     if (res) {
>       return generate_find_by_query(res[1],;
>     }
>   }
> });
> function makeTable(tname) {
>   return Object.create(attributeBasedFinder, {
>     name: { value: tname }
>   });
> };
> Cheers,
> Tom
>> Best regards
>> Mike
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list