RE: Module Comments
> -Original Message- > From: Andreas Rossberg [mailto:rossb...@google.com] > Sent: Thursday, December 6, 2012 11:31 > > On 6 December 2012 16:44, Domenic Denicola > wrote: > > For the record, here's the idea Yehuda and I worked out: > > > > https://gist.github.com/1ab3f0daa7b37859ce43 > > > > I would *really* appreciate if people read it (it's easy reading, I > > promise!) and incorporated some of our concerns and ideas into their > > thinking on module syntax. > > However, the more radical parts of your proposal (allowing arbitrary export > expressions, and arbitrary import patterns) do not work. > > The problem is that imports are not normal variable assignments. They do not > copy values, like normal destructuring, they are aliasing bindings! If you > were to allow arbitrary expressions and patterns, then this would imply > aliasing of arbitrary object properties. Not only is this a completely new > feature, it also is rather questionable -- the aliased location might > disappear, because objects are mutable. Thanks for the feedback Andreas; this is really helpful. It took me a while to figure out what you meant by this, but I think I understand now. However, I think that since the bindings are const bindings, the difference between copying and aliasing is unobservable—is that right? Thus the mental model could be copying in all cases, both top-level and deeper. I think the symmetry I am looking for is that import { x: [a, b], f } from "foo"; should work the same as import foo from "foo"; const { x: [a, b], f } = foo; And I realize the linked gist does not introduce const bindings, but instead let bindings; that's easy enough to fix if it's the right path forward. > You could also consider imports always meaning copying, but then you > exporting a variable will no longer be useful. This is the part that made me question whether I understand what you're saying. What do you mean by "exporting a variable" and "useful"? ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Module Comments
So if you didn't set the anonymous binding in some module "x.js", what would this do: import x from "x.js"; Would x be bound to the module instance or would we get a binding error? For module naming, we'd need to have a different syntax. In earlier > versions of the proposal that was > > module x at "url" > Or: import module x from "url"; Has a nice ring. - Kevin ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: (Map|Set|WeakMap)#set() returns `this` ?
If one thing this is clear from this discussion, it is that different programmers have different preferences (perhaps even changeable depending on use case). So, no single standard API will suit everyone and the language support for different patterns could be improved. Meanwhile, it seems one can get both via proxies (wrapping selected target methods to return this or argument). I had some trouble finding a direct proxy implementation in released engines, so I'm using Tom's harmony-reflect shim in node). See code below, which outputs: $ node --harmony proxy-chain.js undefined { xs: [ 5 ] } { xs: [ 5, 6 ] } { xs: [ 5, 6, 7, 8 ] } 9 { xs: [ 5, 6, 7, 8, 9 ] } The original collection's add method returns undefined (line 1), the this-chained proxy's add returns this (lines 2,3), the value-chained proxy's add returns the added value (line 4). Claus // install npm install harmony-reflect // run: node --harmony proxy-chain.js var Reflect = require('harmony-reflect'); // also shims direct proxies // enable chainable this-return for methods in target function chain_this(target,methods) { return Proxy(target ,{get:function(target,name,receiver){ return methods.indexOf(name)!==-1 ? function(){ target[name].apply(target,arguments); return receiver } : target[name] } }); } // enable chainable value-return for unary! methods in target function chain_value(target,methods) { return Proxy(target ,{get:function(target,name,receiver){ return methods.indexOf(name)!==-1 ? function(arg){ target[name](arg); return arg } : target[name] } }); } function X() { this.xs = []; } X.prototype.add = function(x){ this.xs.push(x) }; // returns void var x = new X(); console.log( x.add(5) , x ); var xt = chain_this(x,['add']); console.log( xt.add(6) ); console.log( xt.add(7).add(8) ); var xv = chain_value(x,['add']); console.log( xv.add(9) , xv ); ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss