> I agree with Andreas. The implicitly-called base level methods are not 
> meta-methods or (spec language) "internal methods". They do not need their 
> own traps. They are base-level property accesses.

Well, certainly that's the way the language currently works. But the way it 
currently works is problematic, because you can't define an object that is 
convertible to string without using the toString name.

> Allowing proxies to trap implicit calls to base-level methods but not 
> explicit calls seems weird. If a Dict should not pollute its pseudo-property 
> namespace with 'toString' and 'valueOf', then it can still delegate those to 
> standard methods on its prototype chain.

This doesn't work. It's a pigeonhole problem. If you allow toString to be 
inherited from the prototype, then it pollutes dictionary lookup. If you don't, 
then string conversion fails. It's not possible to have both.

> And if someone does enter 'toString' or 'valueOf' into a Dict, let the chips 
> fall where they may.

Well of course someone should be allowed to enter 'toString' into a Dict. But 
why shouldn't it be possible to define robust string conversion for an object 
without having to pollute the object's namespace?

> Anything else is more like a new type (typeof type, data type) that's not an 
> object.

I disagree. If you inherit from Object.prototype, then yes, 'toString' has a 
reserved meaning and a prescribed behavior. But since ES5 it's possible to 
create an object that does not inherit from Object.prototype (via 
Object.create), and I see no reason why we should insist on pre-reserving 
meaning for *any* properties on such an object. If you define your own 
prototype hierarchy root, you should be able to give whatever meaning you want 
to whatever names, or even no meaning to any names whatsoever.

> That was proposed separately:
> 
> wiki.ecmascript.org/doku.php?id=strawman:dicts

Yup, I remember writing it. ;-) But ES5 pretty much already gives you the 
ability to define such an object, with the exception of the result of typeof 
and the fact that [[ToString]] and [[ToPrimitive]] break. What I'm proposing is 
that we clean up these places in the semantics that currently look for concrete 
names in favor of something stratified.

One possibility might be to create some private names, à la |iterate|, which 
you could use in place to 'toString' and 'valueOf':

    js> import { toString, valueOf } from "@meta";
    js> var obj = Object.create(null, {});
    js> String(obj)
    TypeError: cannot convert obj to string
    js> obj[toString] = function() { return "hello world" };
    js> String(obj)
    "hello world"

This isn't exactly stratified like proxies, but it at least leaves room to 
unreserve the meaning of 'toString' and 'valueOf'.

Dave

_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to