Catchall proposal

David-Sarah Hopwood david-sarah at
Wed May 6 09:22:35 PDT 2009

David-Sarah Hopwood wrote:
> Brendan Eich wrote:
> [...]
>> I finally found time to write up a proposal, sketchy and incomplete, but
>> ready for some ever-lovin' es-discuss peer review ;-).
> # Catchalls are sometimes thought of as being called for every
> # access to a property, whether the property exists or not.
> The ability to define 'has', 'get', and 'invoke' handlers for the
> case where the property exists, is definitely needed IMHO. Suppressing
> the visibility of a property is potentially as useful as creating a
> "virtual" property, especially for the secure JS subsets.
> I agree however that this is only needed for some use cases, and
> for those case in which it is not needed, it would be inconvenient
> (and less efficient) to require has/get/invoke handlers to perform
> the default action. Defining 'has' and 'hasMissing', 'get' and
> 'getMissing', etc. appears to solve this problem, and I think that
> the extra complexity is justified.

To flesh this out a bit more, I propose the following handlers:

  set(id, val)
  setMissing(id, val)
  invoke(id, args)
  invokeMissing(id, args)

'add' in Brendan's proposal is effectively renamed to 'setMissing',
except that the initial value is passed to 'setMissing' just as it
would be for 'set'.

'call' handles calls to the object using the function call syntax.

'new' handles calls to the object using 'new ...(...)'.
(Note that keywords can be used as property names as of ES5.)

There is no need for a 'deleteMissing' handler.

It is an error (causing defineCatchAll to throw) if both 'foo' and
'fooMissing' are present for foo = {has, get, set, invoke}.

While a catchall is entered for object O, an O.[[InCatchall]] flag
is set that suppresses *all* catchalls for O, i.e. reverting to
the default ES5 behaviour.

Catchall handlers are called with 'this' bound to the object on
which the catchall was triggered.

The 'DefaultAction' idea is not used.

David-Sarah Hopwood ⚥

More information about the es-discuss mailing list