Syntax Sugar for protected state

2016-01-19 Thread 森建
Dear ES discuss subscribers, I'm Kenta Moriuchi, Department of Art and Information Design Kyushu University in Japan I propose `Protected State`. In ES2015: ```js // utility function createProtectedStorage() { const wm = new WeakMap(); return (self, protectedClass) => { const

Re: Capturing groups with a quantifier in look-behind assertions should capture the leftmost substring matched by that group or the rightmost one?

2016-01-19 Thread Claude Pache
> Le 19 janv. 2016 à 08:55, Simon Pieters a écrit : > > On Fri, 15 Jan 2016 16:49:13 +0100, Andrea Giammarchi > wrote: > >> FWIF `RegExp.$1` and others are de-facto standard and removing them would >> break the Web and much more. > > Indeed.

Re: Syntax Sugar for protected state

2016-01-19 Thread Thomas
Could this be achieved with decorators? > On 19 Jan 2016, at 8:31 PM, 森建 wrote: > > Dear ES discuss subscribers, > > I'm Kenta Moriuchi, > Department of Art and Information Design > Kyushu University in Japan > > I propose `Protected State`. > > In ES2015: > > ```js >

Re: Syntax Sugar for protected state

2016-01-19 Thread kdex
@Kenta: Is your model likely to break/leak private data into foreign contexts once you start binding `this`? On the other hand: Should you ever need to bind `this` for class functions? Right now, I'm not entirely sure whether the implementation of "protected" can be runtime-safe. About your

Re: Syntax Sugar for protected state

2016-01-19 Thread Andrea Giammarchi
It could be achieved with decorators but it won't be the same. On a side note, that `Object.assign` operation doesn't do what you think it does, there are better patterns (boilerplates, actually ...) to copy own properties over within their descriptors, if different from enumerable data

Re: Syntax Sugar for protected state

2016-01-19 Thread Andrea Giammarchi
IIRC the difference between protected and private is that a private field works within the class but not subclasses while protected means from a subclass you can use directly `protected.whatever` even if `whatever` is not defined but it's inherited from the super class. Private is private, and

Annex B.3.3 substantially changes strict vs non-strict semantics

2016-01-19 Thread Kevin Gibbons
I'm not sure if this is well-known; it was certainly surprising to me. Consider the following program: `let func = () => 0; (function(){ { function func() { return 1; } } return func(); })();` The return value of the second function depends on whether this program is

Re: Annex B.3.3 substantially changes strict vs non-strict semantics

2016-01-19 Thread Mark S. Miller
On Tue, Jan 19, 2016 at 9:54 AM, Kevin Gibbons wrote: > I'm not sure if this is well-known; it was certainly surprising to me. > > Consider the following program: > `let func = () => 0; > > (function(){ > { > function func() { > return 1; > } > } >

Re: Annex B.3.3 substantially changes strict vs non-strict semantics

2016-01-19 Thread Andrea Giammarchi
FWIW I think that's expected. Strict mode would throw otherwise but of course if you have an outer scope reference to whatever you are invoking that's indeed what you invoke. Making it behave similarly in both strict and non strict would be a mistake for the existing sloppy code but I agree that

Re: Syntax Sugar for protected state

2016-01-19 Thread Jordan Harband
It would be helpful to link to gists or github repos rather than pasting code inline. You may also be interested to read this proposal: https://github.com/wycats/javascript-private-state On Tue, Jan 19, 2016 at 8:43 AM, 森建 wrote: > @Andrea Giammarchi > > Thank you for

Re: Error stack strawman

2016-01-19 Thread Jonathan Kingston
Hi Mark, Sorry for the delay, thank you for that response it was very useful. Do you think it would make sense to open an API for Error stack that would be purely based upon user agent implementation? I'm not familiar with the internals of the traces but I have seen comments mentioning

Re: Re: Syntax Sugar for protected state

2016-01-19 Thread Andrea Giammarchi
to be clear: no, Object.assign does not copy accessors in a meaningful way, it copies the result of the getter, not its descriptor. That page at MDN has also many errors, including the function myAssign that copies keys but not Symbols. Gonna fix that, best regards On Tue, Jan 19, 2016 at 1:16

Re: Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
@Thomas >Could this be achieved with decorators? I want to get Syntax Sugar. But I didn't have an idea using decorators, thank you! @kdex >About your nomenclature: Why name it `protected` rather than `private`? Am I missing a key difference between the two here? This is not `private`

Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
Sorry, I misunderstood descriptor and accessor. I try it!! ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
I make it! ```js "use strict"; // utility function createProtectedStorage() { const wm = new WeakMap(); return (self, protectedClass) => { const map = wm.get(self); if(protectedClass == null) { if(map) { return map; } else { const ret =

Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
Sorry, I must use `Object.getOwnPropertySymbols`. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss

Re: Syntax Sugar for protected state

2016-01-19 Thread Andrea Giammarchi
`for(let key of [ ...Object.getOwnPropertyNames(map), ...Object.getOwnPropertySymbols(map) ])` ... or ... `for(let key of Reflect.ownKeys(map))` On Tue, Jan 19, 2016 at 4:10 PM, 森建 wrote: > maybe okay. > > ```js > "use strict"; > > // utility > function

Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
maybe okay. ```js "use strict"; // utility function createProtectedStorage() { const wm = new WeakMap(); return (self, protectedClass) => { const map = wm.get(self); if(protectedClass == null) { if(map) { return map; } else { const ret =

Re: Syntax Sugar for protected state

2016-01-19 Thread 森建
@Andrea Giammarchi Thank you for supporting my code, I got JavaScript knowledge a lot! @Subscribers If there is not any problems, would you kindly discuss about this syntax sugar? ___ es-discuss mailing list es-discuss@mozilla.org