Igor Baklan (2016-05-14T11:22:39.000Z)
io.baklan at gmail.com (2016-05-14T13:36:47.714Z)
> I would like to point out that this particular example could be done in terms of existing proxies ... Yes, for this simplistic case that you properly mentioned, operation `[]` is enough, but when i writing that example I rather keep in mind js [Map]( https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) and object keys. So the goal is also simplified syntax of accessing and mutating maps, like: ```js var map = new Map(); var key = {foo: "bar"}; var val = {some: "value"}; map(key) = val; // same as map.set(key, val) if js has "`_()=_`" operation console.assert(map(key) === val); // same as (map.get(key) === val) map.delete(key); console.assert(map(key) == null); ``` If `"_()=_"` operation will be available in language, then anyone will be able to implement his own `MultiDimMap` multidimensional map (on top of existing single-dimensional map), with usage similar to following ```js var map = new MultiDimMap(); var key0 = {foo: "bar"}; var key1 = {foo1: "bar1"}; var val = {some: "value"}; map(key0, key1) = val; console.assert(map(key0, key1) === val); map.delete(key0, key1); console.assert(map(key0, key1) == null); ``` Also to provide more complete information about current state of similar feature in other languages, it would be good to take a look on [C# indexers](https://msdn.microsoft.com/en-us/library/6x16t2tx.aspx). It also provides extensive possibility to implement `"_[]=_"` operation with arbitrary number of arguments, so in case of C# expressions like `obj.idxr[arg1, arg2, ... , argN] = val` is pretty valid (if `obj.idxr` indexer properly implemented in `obj`). But this feature looks for me more ambiguous with current implementation of Proxy object (more specifically with current definition of `set` and `get` methods of [proxy handler]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler)). In particular `set` states signature: ``` set: function(target, property, value, receiver) ``` but if we will have a list of arguments (like `obj[arg1, ... , argN]`) then what should be passed to `property` argument, if it will be `property == [arg1, ... , argN]` then it looks like OK, but if we pass only one argument, like `obj[Array.from([arg1, ... , argN])]` what should be in `property` , of course it should be rather `property == [ [arg1, ... , argN] ]` but still it looks little bit ambiguous. So for me [Scala](http://docs.scala-lang.org/cheatsheets/) approach for "indexing" with `"()"` / `"()="` operations looks more nice. (More information about Scala approach to `apply`/`update` - `"()"` / `"()="` can be found at https://www.scala-academy.com/tutorials/scala-apply-update-methods-tutorial, also about maps: https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch11s15.html, http://docs.scala-lang.org/overviews/collections/maps#operations-in-class-mutablemap )
io.baklan at gmail.com (2016-05-14T13:30:51.214Z)
> I would like to point out that this particular example could be done in terms of existing proxies ... Yes, for this simplistic case that you properly mentioned, operation `[]` is enough, but when i writing that example I rather keep in mind js [Map]( https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Map) and object keys. So the goal is also simplified syntax of accessing and mutating maps, like: ```js var map = new Map(); var key = {foo: "bar"}; var val = {some: "value"}; map(key) = val; // same as map.set(key, val) if "`_()=_`" operation would be properly implemented on Map console.assert(map(key) === val); // same as (map.get(key) === val) map.delete(key); console.assert(map(key) == null); ``` If `"_()=_"` operation will be available in language, then anyone will be able to implement his own `MultiDimMap` multidimensional map (on top of existing single-dimensional map), with usage similar to following ```js var map = new MultiDimMap(); var key0 = {foo: "bar"}; var key1 = {foo1: "bar1"}; var val = {some: "value"}; map(key0, key1) = val; console.assert(map(key0, key1) === val); map.delete(key0, key1); console.assert(map(key0, key1) == null); ``` Also to provide more complete information about current state of similar feature in other languages, it would be good to take a look on [C# indexers](https://msdn.microsoft.com/en-us/library/6x16t2tx.aspx). It also provides extensive possibility to implement `"_[]=_"` operation with arbitrary number of arguments, so in case of C# expressions like `obj.idxr[arg1, arg2, ... , argN] = val` is pretty valid (if `obj.idxr` indexer properly implemented in `obj`). But this feature looks for me more ambiguous with current implementation of Proxy object (more specifically with current definition of `set` and `get` methods of [proxy handler]( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler)). In particular `set` states signature: ``` set: function(target, property, value, receiver) ``` but if we will have a list of arguments (like `obj[arg1, ... , argN]`) then what should be passed to `property` argument, if it will be `property == [arg1, ... , argN]` then it looks like OK, but if we pass only one argument, like `obj[Array.from([arg1, ... , argN])]` what should be in `property` , of course it should be rather `property == [ [arg1, ... , argN] ]` but still it looks little bit ambiguous. So for me [Scala](http://docs.scala-lang.org/cheatsheets/) approach for "indexing" with `"()"` / `"()="` operations looks more nice. (More information about Scala approach to `apply`/`update` - `"()"` / `"()="` can be found at https://www.scala-academy.com/tutorials/scala-apply-update-methods-tutorial, also about maps: https://www.safaribooksonline.com/library/view/scala-cookbook/9781449340292/ch11s15.html, http://docs.scala-lang.org/overviews/collections/maps#operations-in-class-mutablemap )