I would like to point out that this particular example could be done in
terms of existing proxies now:
```js
var sttFunc = new Proxy({}, {
get(target, key) {
console.log("get: [", key, "]");
return key;
},
set(target, key, value) {
console.log("set: [", key, "] = ", val);
return true; // success
}
});
// Usage:
sttFunc["key"] = "value"; // set: [key] = value
sttFunc["key"]; // get: [key]
```
On Thu, May 12, 2016, 15:02 Jason Orendorff <[email protected]>
wrote:
> The nice thing about @@symbol-named methods is that we *don't* have to
> extend the Proxy API for them. They're just method calls.
>
> This is why there's no hasInstance Proxy trap. `instanceof` basically
> boils down to a method call, and we already have Proxy traps for
> method calls: `get` and `apply`.
>
> It's a good thing, too, because adding a new Proxy trap is a last
> resort. Just from a conceptual standpoint, the less complicated
> objects are, the better; just because there are 14 *fundamental*
> operations on objects doesn't mean we're eager to add more. But
> there's also an inherent compatibility issue. Whenever you add a new
> trap, the deal is, all existing Proxy handlers were written without
> consideration for the new operation. So old code, used in combination
> with the new language feature, would tend to break.
>
> Cheers,
> -j
>
>
> On Thu, May 12, 2016 at 9:42 AM, Igor Baklan <[email protected]> wrote:
> > It would be nice to "bring sense" to expressions like "obj(a1, ... , aN)
> =
> > val". (like "obj(x) = y")
> > In Scala langue it defined in pretty clear and simple way:
> >
> > "obj(a1, ... , aN)" <==> "obj.apply(a1, ... , aN)"
> > "obj(a1, ... , an) = val" <==> "obj.update(a1, ... , aN, val)"
> >
> > Of course this applied only to that cases when obj was not defined like
> > method (in case of regular methods "mth(args) = val" will cause compile
> time
> > error).
> > So in Scala even arrays and maps are accessed and updated using "()"
> > operator
> >
> > js( arr[index] = val ) <==> scala( arr(index) = val )
> >
> > (see http://www.scala-lang.org/api/2.10.0/index.html#scala.Array ,
> >
> http://docs.scala-lang.org/overviews/collections/maps#operations-in-class-mutablemap
> > , etc)
> >
> > So the proposals are:
> >
> > (1) to introduce symbols like @@apply and @@update with very similar to
> > Scala meaning (for cases when 'obj.sttFunc' is not a function)
> >
> > "obj.sttFunc(a1, ... , aN) = val" ==> "obj.sttFunc[Symbol.update]
> > (obj.sttFunc, obj, [a1, ... , aN], val)"
> > "obj.sttFunc(a1, ... , aN)" ==> "obj.sttFunc[Symbol.apply]
> (obj.sttFunc,
> > obj, [a1, ... , aN])"
> >
> > (2) to extend Prxoy object specification to support update action along
> with
> > apply action:
> >
> > I would like to write something similar to
> >
> > var target = {
> > jsApply: function(key){
> > console.log("apply: ", key);
> > return key;
> > },
> > jsUpdate: function(key, val){
> > console.log("update: (", key, ") = ", val);
> > return val;
> > }
> > };
> > var sttFunc = new Proxy(target, {
> > apply: function(target, thisArg, argumentsList) {
> > target.jsApply.apply(thisArg, argumentsList);
> > },
> > update: function(target, thisArg, argumentsList, assignValue) {
> > target.jsApply.apply(thisArg,
> > Array.from(argumentsList).concat([assignValue]));
> > }
> > });
> >
> > And then run it as following
> >
> >> sttFunc ("key") = "value";
> >
> > update: ( key ) = value
> >
> >> sttFunc ("key");
> >
> > apply: key
> > "key"
> >
> >
> > _______________________________________________
> > es-discuss mailing list
> > [email protected]
> > https://mail.mozilla.org/listinfo/es-discuss
> >
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss