I find this proposal backwards. It requires an expeession as the right
hand side. Alex proposed something similar a long time ago. He
suggested using '!' instead of '.'. This is important because the
common use case we want to solve is to make 'obj.foo.bind(foo)' be
written as 'obj!foo'. With your proposal I have to do let f = obj.foo;
obj::f which is even longer than the original.
Another important, but orthogonal part of his proposal was to have
obj!meth === obj!meth
expression!propertyName
// desugars to
// WeakMap to cache the lookup.
let objectMap = new WeakMap;
do {
let object = expression;
let map;
if (!(map = objectMap.get(object)) {
map = new Map;
objecMap.set(object, map);
}
let result;
if ((result = map.get("propertyName")))
return result;
result = object.propertyName.bind(object);
map.set("propertyName", result);
result;
}
One option would be to use the function instead of the property name
as the key in the inner map.
On Wed, Mar 28, 2012 at 10:37, David Herman <[email protected]> wrote:
> On Mar 27, 2012, at 9:14 PM, Russell Leggett wrote:
>
>> I'm sure this is a bit of a tangent, but the other major related case is
>> passing a "method" as an argument but needing to retain the correct "this".
>> Obviously, that is what bind was meant for, but that is inconvenient when
>> passing methods for the same reason it would be inconvenient for anonymous
>> functions.
>>
>> What if we had a shorthand for bind that worked in both of these cases...
>
> I have a strawman on this topic:
>
> http://wiki.ecmascript.org/doku.php?id=strawman:bind_operator
>
> I agree it's a real need. Just like ... will provide convenient,
> high-fidelity (e.g., insensitive to Function.prototype monkey-patching)
> syntax for .apply, we should also have an operator that provides convenient,
> high-fidelity syntax for .call and .bind. I believe a single operator can
> provide both.
>
> Dave
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
--
erik
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss