Re: Generator Arrow Functions
+1 on arrowed generators! Have being actively using generators last month have being wishing they could be like arrows, although syntax I've being thinking of was (x, y) * { } BTW given that generators are used as a method on iterators wouldn't it make sense to consider syntax for generator members in a classes syntax ?? My hope is in ES6 we would just use class syntax for methods arros for functions making function a legacy On Monday, November 18, 2013, Brendan Eich wrote: Ѓорѓи Ќосев wrote: Its harder to scan whether this is a generator arrow function or a normal arrow function because the star is too far away: someFunction(*(someArgument, anotherArgument) = { ... code ... }); compared to this form, where its immediately obvious that this is not a regular function, just by looking at the composed symbol (arrow-star) someFunction((someArgument, anotherArgument) =* { ... code ... }); I buy it. This is what I'll propose next week as concrete syntax. It's a small point, but the rationale is the star goes after the first token that identifies the special form as a function form. For generator functions, that token is 'function'. For arrows, it is '='. /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Generator Arrow Functions
Oh I must have missed that, never mind then thanks Axel for pointing out. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2013-11-20 at 03:22 , Axel Rauschmayer wrote: +1 on arrowed generators! Have being actively using generators last month have being wishing they could be like arrows, although syntax I've being thinking of was (x, y) * { } BTW given that generators are used as a method on iterators wouldn't it make sense to consider syntax for generator members in a classes syntax ?? It’s already in the spec: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generator-function-definitions My hope is in ES6 we would just use class syntax for methods arros for functions making function a legacy My hope, too. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) home: rauschma.de (http://rauschma.de/)twitter: twitter.com/rauschma (http://twitter.com/rauschma) blog: 2ality.com (http://2ality.com/) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Protocol library as alternative to refinements (Russell Leggett)
I thought you may find it interesting that while back I wrote library to full fill my desire for clojure like protocols wrote a blog post about it: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post https://github.com/Gozala/protocol In a process of using it I discovered that it was not very javascripty did another take on this in form of different library that let's you create functions and provide it's polymorphic implementations: https://github.com/Gozala/method I my team members found this really useful in real project that let us separate contracts between components that would share some interface but are not necessarily related. Initially library was generated unique names for each function that you create, although I hope to use private symbols once they're available: var each = method() In nutshell it would do something along this lines const method = () = { const id = Math.random().toString(32).substr(2) const f = (self, …args) = self[id](self, …args) f.toString = () = id return f } Although dispatch is little more complicated to incorporate host objects and default implementations. Library also does not mutate bulit-ins instead keeps internal hashes for them. Anyhow this enables defining implementations for this function per type: MyIterable.prototype[each] = (myIterable, f) = …. Unfortunately later I had to move towards `method(your-own-unique-name)` approach (although old one is still there), because users on nodejs would constantly run into issues, because of nom's nutty habit of duplicating dependencies. That caused same library copy to have `each` functions with different identifiers :( I'm afraid we'll face same issues with private symbols as well. A while ago I also proposed TC39 to consider a small change to private symbols such that, created symbols would actually be invokable: import Symbol from @symbol; const each = new Symbol(each, true); each(iterator, x = x + 1) Where above line would desugar to: iterator[each](iterator, x = x + 1) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2013-10-23 at 13:02 , Russell Leggett wrote: On Wed, Oct 23, 2013 at 2:57 PM, Benjamin (Inglor) Gruenbaum ing...@gmail.com (mailto:ing...@gmail.com) wrote: Yes, this looks solid and definitely like something I'll use. I'll try to go through use cases and find problems during the weekend. What do you think would be the fastest way to get a prototype something working to play with? Well the library itself could be implemented now, but without :: you wouldn't get the nice syntax. I've been looking into Traceur a bit to see how hard it would be to add :: - its some fairly simple syntax sugar. - Russ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Standard errors types with file line info ?
Hi, My apologies if that's being already discussed (have not being following this list actively lately). I would be really love if error types could be standardised such that `fileName`, `lineNumber` information could be taken from them reliably. It would be also great if error.stack was in JSON structure instead of string that is not easy to work with. It would be yet even better if optional fileName, lineNumber, columnNumber could be specified at / post error construction time, for example spidermonkey already has support for this: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Error Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: WeakMap better than Private Symbols? (was: direct_proxies problem)
Here is a link to a documentatin for the weak map based solution that Kris mentioned: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/modules/sdk/core/namespace.html We find it invaluable and use for storing private field. Inheritance works, but we did not found that feature all that useful in practice, probably because we use that only for data fields There is also another experiment that I found to be a lot more useful for non data properties like methods https://github.com/gozala/method I also honestly wish private names would just be it On Thursday, January 10, 2013, Kris Kowal wrote: As an aside, Irakli Gozashvili and I independently realized that you could use a WeakMap for parallel objects with inheritance. Very similar to Brendan’s createStorage, we put together a parallel universe constructor. function Parallel(root) { var parallel = new WeakMap(); root = root || null; function get(object) { if (!parallel.has(object)) { parallel.set(object, Object.create(get(Object.getPrototypeOf(object; } return parallel.get(object); } return get; } Irakli’s was a Namespace constructor that appeared somewhere in the Mozilla Add-on toolkit, but the links have gone stale. Kris Kowal ___ es-discuss mailing list es-discuss@mozilla.org javascript:; https://mail.mozilla.org/listinfo/es-discuss -- Typed on tiny virtual keyboard ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: A Variation on ES Modules
I have added few comments to https://gist.github.com/4382710 Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Friday, 2012-12-28 at 10:21 , Kevin Smith wrote: Just to finalize this thread, I updated the gist based on comments from Andreas: https://gist.github.com/4382710 It includes syntax for proper inline modules, and an extension syntax for pre-loading (aka concatenating). It also brings the syntax for module aliasing closer to the previous harmony proposal: module M = m.js; module N = M.N; { Kevin } ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
API to identify host objects
Lately I have being struggling with an implementation differences of host (DOM) objects across the browsers. So far only reliable way I could find to identify host objects is by a following assertion: object.constructor.call === void(0) Behaviour seems to be consistent across FF, Opera, Safari, and Chrome (Don't have windows to test on IE). I think it would be great if there was some standardised way to identify host objects. My personal use case is polymorphic method dispatch library https://github.com/Gozala/method that has same semantics as clojure protocols. Method implementations for host objects and built-ins are stored in the separate dictionary to avoid memory leaks and to support objects from diff JS contexts / frames / compartments. If you know of a better of identifying host objects I would really love to know that too. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: API to identify host objects
Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Monday, 2012-11-12 at 14:30 , Brendan Eich wrote: Irakli Gozalishvili wrote: Lately I have being struggling with an implementation differences of host (DOM) objects across the browsers. So far only reliable way I could find to identify host objects is by a following assertion: object.constructor.call === void(0) Wow, that's not bad (except for the overparenthesized 0 :-P). Behaviour seems to be consistent across FF, Opera, Safari, and Chrome (Don't have windows to test on IE). I think it would be great if there was some standardised way to identify host objects. There does seem to be some fuzzy need, but given jQuery's isPlainObject (http://api.jquery.com/jQuery.isPlainObject/) the way people check varies. My personal use case is polymorphic method dispatch library https://github.com/Gozala/method that has same semantics as clojure protocols. Method implementations for host objects and built-ins are stored in the separate dictionary to avoid memory leaks and to support objects from diff JS contexts / frames / compartments. Doesn't the latter (cross-frame/etc.) need affect native objects too? Yes it does and method implementations for built-ins are also stored in a separate hash. Detecting built-ins seems to be a lot easier though since Object.prototype.toString.call(value) returns [object Error], [object Number], … etc... /be If you know of a better of identifying host objects I would really love to know that too. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Fixing instanceof / typeof
Most recently I needed that to do polymorphic function dispatch on input argument type. More specifics can be found here: https://github.com/Gozala/method/blob/master/core.js#L121-127 This case may be quite exotic, but I remember running into this quite a lot, can't use cases unfortunately. BTW underscore has bunch of this utilities too: http://underscorejs.org/#objects that making me believe it's common enough case. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Monday, 2012-10-15 at 17:59 , Brendan Eich wrote: Just curious: why did you need a nominal type test, rather than a duck type test? /be Irakli Gozalishvili wrote: Hi, Today I had to deal with a value type detection in JS and that reminded me of all the pain associated with it, especially when dealing with values that may have come across the diff compartment / frame / context. `instanceof` is useless when dealing with objects from diff contexts, `typeof` is also pretty limited in a sense that it can detect weather value is array, error, map, set, etc.. not to mention it's awkwardnesses… Only solution that seems to work toady that is adopted by most popular JS libraries is: function type(value) { return Object.prototype.toString.call(value).split(' ')[1].split(']')[0].toLowerCase() } I don't actually know if that's supposed to work according to spec or if it's just an implementation coincidence that happen to work. Either way I would really welcome some standard solution preferably via function form (so that can be polyfilled today) to do type detection for all the built-ins and host objects. Aside main issue, it would be great if solution was compatible with mozilla's xpcom components too where one object my be queried with multiple interfaces and there for have multiple types. Also, above hack does not works with XPCOMs as Object.prototype.toString returns [object XPCWrappedNative_NoHelper], while actual toString returns something little more useful [xpconnect wrapped (nsISupports, nsIURI, nsIURL)] Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Fixing instanceof / typeof
Hi, Today I had to deal with a value type detection in JS and that reminded me of all the pain associated with it, especially when dealing with values that may have come across the diff compartment / frame / context. `instanceof` is useless when dealing with objects from diff contexts, `typeof` is also pretty limited in a sense that it can detect weather value is array, error, map, set, etc.. not to mention it's awkwardnesses… Only solution that seems to work toady that is adopted by most popular JS libraries is: function type(value) { return Object.prototype.toString.call(value).split(' ')[1].split(']')[0].toLowerCase() } I don't actually know if that's supposed to work according to spec or if it's just an implementation coincidence that happen to work. Either way I would really welcome some standard solution preferably via function form (so that can be polyfilled today) to do type detection for all the built-ins and host objects. Aside main issue, it would be great if solution was compatible with mozilla's xpcom components too where one object my be queried with multiple interfaces and there for have multiple types. Also, above hack does not works with XPCOMs as Object.prototype.toString returns [object XPCWrappedNative_NoHelper], while actual toString returns something little more useful [xpconnect wrapped (nsISupports, nsIURI, nsIURL)] Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Some questions about Private Name Objects
Hey Dean, I also really love clojure protocols and in fact tried to propose few extensions for private names to make them little more usable as such: https://mail.mozilla.org/pipermail/es-discuss/2012-June/023657.html https://gist.github.com/2967124 Unfortunately thread did not got any replies from anyone. That being said I did couple of experiments in these area: Implemented clojure like protocols as library: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post But after using it for some time I realised it was not very javascripty, so I have prototyped a more minimalistic version, which I'm using happily since then: https://github.com/Gozala/method I still really wish we could make private names callable such that: var method = Name() method(object, arg1, arg2) = object[method](arg1, arg2) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-09-13 at 14:46 , Dean Landolt wrote: The real point I'm trying to make is that Name objects give us something akin to clojure's protocols. Imagine an orm protocol -- this is just a set of names that must exist on an object (or its proto chain). An object can implement any number of protocols (or interfaces, or whatever) without fear of conflict. You can easily override any implementation so long as you have a handle on the appropriate name object. This is easier, better looking and more correct than anything we can do today. It's not too disimilar from using using instanceof as a brand, but without the pitfalls (it doesn't fall flat crossing sandbox boundaries). This is a safe and flexible inheritance model that works just as a js programmer would expect, all without begging for mutable or multiple prototypes. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Arrow functions as methods
Thanks Brendan for explaining the problem, I can see how that can get confusing. What it is a failure? While fat arrows solve a problem (or rather simplify) with .bind(this) they do introduce a new one. Namely they can't be used as methods. Which would not have being a problem if we had both thin fat arrows. That basically means that whenever I have to explain someone how to use X I can't tell forget about old functions, I have to teach about one more flavor of it. That's what I see as failure. No, not as methods as commonly expressed in object literals. Those get other shorthand. They do get other shorthand, but that's makes interoperability between OO functional only harder, you will have to choose either red or blue pill. While I really wish we could write code in either style and let users decide which style they want to use it. People have to say what they mean, they do not get implicit uncurrying of |this| as a first parameter. Yes I do understand this point. My suggestion clearly has issues, but I'm happy to get any other solution that would be issue free and would allow reuse of functions as methods. It could be thin arrow or explicit syntax to expressing desire to get `this` as parameter: var map = (this, f) = reduce(this, (result, x) = result.concat([ f(x) ]), []) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 23:02 , Brendan Eich wrote: Gordon Brander wrote: I noticed an alternative solution to this problem in the ES Wiki:http://wiki.ecmascript.org/doku.php?id=harmony:arrow_function_syntax#deferred (see optional leading `this` initializer). As I understand it, that would give us some sort of special delimiter for specifying a soft-bound `this` context on a thin-arrow, e.g. in pseudo-code: foo(o | a, b) ...or some-such. That syntax was for expressions and definitions of functions, not for calls. The idea was to enable parameter default values for |this|. It won't do what Irakli wants. Soft-bind is not going to fly, see https://mail.mozilla.org/pipermail/es-discuss/2012-June/023221.html, https://mail.mozilla.org/pipermail/es-discuss/2012-June/023202.html, and mainly https://mail.mozilla.org/pipermail/es-discuss/2012-May/023002.html. Implicitly shifting |this| in call expressions to the front of the actual argument list is similarly painful in overhead for implementors, besides making the dynamic two args, or only one? hazard depending on how a callee called from a polymorphic site happened to be expressed. What Python does is a bit different: obj.foo(arg) is Class_of_obj.foo(obj, arg) not just foo(obj, arg) for some identifier-expression 'foo'. But this depends on classes in Python, which are not in any way analogous to = function expressions. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Arrow functions as methods
It is true that on could wrap arrow function into vintage one in order to reuse it as a method, but that is a poor mans workaround. As of motivation, all I really want is to have a synergy of different paradigms that are in the language. What I really mean by that is, if one writes in a functional style: var map = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) That should be reusable in OO code without any changes or wrappers: List.prototype.map = map List().map((x) = x + 1) Also this complements another idea that I have posted a while ago: https://mail.mozilla.org/pipermail/es-discuss/2012-June/023657.html Where I proposed to make private names functions: var method = Name() method(object, arg) // is just a sugar for object[method](arg) This will enable people to write code in OO or functional style and make it usable in other style: var map = Name(); List.prototype[map] = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) Which one will be able to us in a functional style map(list, f) or in OO list[map](f) Also even if suggested changes to private names won't take of, it's still can be implemented as a library: https://github.com/Gozala/method There for a way to author functions that also can be used as methods is relevant. Thin arrows would probably also solve this problem. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 09:39 , Claus Reinke wrote: function map(f) { return this.reduce((result, value) = result.concat([ f(value) ]), []) } .. var map = (list, f) = list.reduce((result, value) = result.concat([ f(value) ]), []) Not sure I got your motivation, but would this help? function fn(f) { return f(this) } // provide 'this' as explicit arg let map = it = f = it.list.reduce((result, value) = result.concat([ f(value) ]), []) let obj = { map: fn(map), list: [1,2,3] }; // wrap map as method obj.map(x = x+1); map( {list:[1,2,3]} )(x = x+1); Claus ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Arrow functions as methods
I think more general problem with arrow functions is that they can not capture object on which method call happened: object.foo(bar) If `object.foo` is an arrow function it has no way of knowing weather it was invoked as a function or a method. Neither it get's reference to an `object`. This makes composition between functional OO styles components hard. Passing owner `object` of the arrow method as first argument solves this problem, by making object.foo(bar) just a sugar for var foo = object.foo; foo(object, bar); Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 10:23 , Irakli Gozalishvili wrote: It is true that on could wrap arrow function into vintage one in order to reuse it as a method, but that is a poor mans workaround. As of motivation, all I really want is to have a synergy of different paradigms that are in the language. What I really mean by that is, if one writes in a functional style: var map = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) That should be reusable in OO code without any changes or wrappers: List.prototype.map = map List().map((x) = x + 1) Also this complements another idea that I have posted a while ago: https://mail.mozilla.org/pipermail/es-discuss/2012-June/023657.html Where I proposed to make private names functions: var method = Name() method(object, arg) // is just a sugar for object[method](arg) This will enable people to write code in OO or functional style and make it usable in other style: var map = Name(); List.prototype[map] = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) Which one will be able to us in a functional style map(list, f) or in OO list[map](f) Also even if suggested changes to private names won't take of, it's still can be implemented as a library: https://github.com/Gozala/method There for a way to author functions that also can be used as methods is relevant. Thin arrows would probably also solve this problem. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 09:39 , Claus Reinke wrote: function map(f) { return this.reduce((result, value) = result.concat([ f(value) ]), []) } .. var map = (list, f) = list.reduce((result, value) = result.concat([ f(value) ]), []) Not sure I got your motivation, but would this help? function fn(f) { return f(this) } // provide 'this' as explicit arg let map = it = f = it.list.reduce((result, value) = result.concat([ f(value) ]), []) let obj = { map: fn(map), list: [1,2,3] }; // wrap map as method obj.map(x = x+1); map( {list:[1,2,3]} )(x = x+1); Claus ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Arrow functions as methods
We've been around that block and will go again. If we want convenient unbound-this function syntax, - stands ready. I proposed it along with = originally but it was cut by TC39 during our March meeting in order to achieve consensus on =. Yeah I'm aware of that, but problem as I see is that new fat arrow functions can not fully replace existing functions. In combination with thin arrows they would but since they have being cut ended up with a dependency on an old style function in order to wrap arrows to make them usable as methods. I consider it's a failure. object.foo(bar) If `object.foo` is an arrow function it has no way of knowing weather it was invoked as a function or a method. Neither it get's reference to an `object`. This makes composition between functional OO styles components hard. No, I don't think so. The ability of a function to ignore any parameter, including |this|, may frustrate composition, but the contract of an API includes mandatory parameterization of any funargs. People deal with this pretty well in practice, usually by writing small-world codebases and wrapping anything unknown that needs contract-enforcement along these lines. Well but as pointed out above you need an old style functions to make arrows usable as methods, I think such dependency is very unfortunate. Passing owner `object` of the arrow method as first argument solves this problem, by making object.foo(bar) just a sugar for var foo = object.foo; foo(object, bar); This completely breaks functional abstraction, of course. f(a) and o.m(a) in JS should never pass more than one actual parameter to the callee, however it was declared or expressed. Unfortunately I still do not understand why is that a problem, specially since Claus's wrapper can be used to achieve that. It's just I think it makes it a much better default. /be Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 10:23 , Irakli Gozalishvili wrote: It is true that on could wrap arrow function into vintage one in order to reuse it as a method, but that is a poor mans workaround. As of motivation, all I really want is to have a synergy of different paradigms that are in the language. What I really mean by that is, if one writes in a functional style: var map = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) That should be reusable in OO code without any changes or wrappers: List.prototype.map = map List().map((x) = x + 1) Also this complements another idea that I have posted a while ago: https://mail.mozilla.org/pipermail/es-discuss/2012-June/023657.html Where I proposed to make private names functions: var method = Name() method(object, arg) // is just a sugar for object[method](arg) This will enable people to write code in OO or functional style and make it usable in other style: var map = Name(); List.prototype[map] = (list, f) = reduce(list, (result, value) = result.concat([ f(value) ]), []) Which one will be able to us in a functional style map(list, f) or in OO list[map](f) Also even if suggested changes to private names won't take of, it's still can be implemented as a library: https://github.com/Gozala/method There for a way to author functions that also can be used as methods is relevant. Thin arrows would probably also solve this problem. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-07-11 at 09:39 , Claus Reinke wrote: function map(f) { return this.reduce((result, value) = result.concat([ f(value) ]), []) } .. var map = (list, f) = list.reduce((result, value) = result.concat([ f(value) ]), []) Not sure I got your motivation, but would this help? function fn(f) { return f(this) } // provide 'this' as explicit arg let map = it = f = it.list.reduce((result, value) = result.concat([ f(value) ]), []) let obj = { map: fn(map), list: [1,2,3] }; // wrap map as method obj.map(x = x+1); map( {list:[1,2,3]} )(x = x+1); Claus ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Arrow functions as methods
Hi, I just wanted to bring up IMO important limitation of arrow functions. They do solve unbound `this` issues when used as a callback, but they also introduce unfortunate limitation. Arrow functions can not really be used as methods. For example it was great that in JS one could write a function that could be used as a method or as function: function map(f) { return this.reduce((result, value) = result.concat([ f(value) ]), []) } // Use as method foo.map = map; foo.map((x) = x + 1) // Use as function map.call(bar, (x) = x + 1) I would say still is unfortunate that such reusable functions had do be called via special `.call` but never the less code sharing was simple to do. Now arrow functions as they stand today can not be used in that manner as `this` refers to the outer scope `this` for a good reason. But it still would be nice to allow reusing them as methods, in fact they could be even solve current `map.call(…)`. What I'd like to propose is borrow successful idea from other languages and make: foo.map((x) = x + 1) be a sugar for map(foo, (x) = x + 1) If `map` is an arrow function That would make (arrow) functions a lot more composable: var map = (list, f) = list.reduce((result, value) = result.concat([ f(value) ]), []) List.prototype.map = map List().map((x) = x + 1) or map(List(), (x) = x + 1) or map([ 1, 2, 3 ], (x) = x + 1) I think this would make a good synergy of OO and functional styles in JS Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Arrow functions as methods
One more thing if some reason one want's to call arrow method without passing an owner it's still easy: (List.prototype.map)([ 1, 2, 3 ], (x) = x + 1) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Tuesday, 2012-07-10 at 15:02 , Irakli Gozalishvili wrote: Hi, I just wanted to bring up IMO important limitation of arrow functions. They do solve unbound `this` issues when used as a callback, but they also introduce unfortunate limitation. Arrow functions can not really be used as methods. For example it was great that in JS one could write a function that could be used as a method or as function: function map(f) { return this.reduce((result, value) = result.concat([ f(value) ]), []) } // Use as method foo.map = map; foo.map((x) = x + 1) // Use as function map.call(bar, (x) = x + 1) I would say still is unfortunate that such reusable functions had do be called via special `.call` but never the less code sharing was simple to do. Now arrow functions as they stand today can not be used in that manner as `this` refers to the outer scope `this` for a good reason. But it still would be nice to allow reusing them as methods, in fact they could be even solve current `map.call(…)`. What I'd like to propose is borrow successful idea from other languages and make: foo.map((x) = x + 1) be a sugar for map(foo, (x) = x + 1) If `map` is an arrow function That would make (arrow) functions a lot more composable: var map = (list, f) = list.reduce((result, value) = result.concat([ f(value) ]), []) List.prototype.map = map List().map((x) = x + 1) or map(List(), (x) = x + 1) or map([ 1, 2, 3 ], (x) = x + 1) I think this would make a good synergy of OO and functional styles in JS Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: private name methods ?
I have realized this idea in a JS library: https://github.com/Gozala/method Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-06-21 at 12:31 , Irakli Gozalishvili wrote: I get few comments on twitter regarding this: So the idea is that a private name object is callable, and name(obj, ...rest) delegates to obj[name](...rest)? Yeah thats is a primary idea: name(object, …rest) = object[name](…rest) Although my hope is that `null` and `undefined` could also be supported in some way. Note that with following will work only if `object` is from the same JS context (iframe): Object.prototype[name] = function() { … } name(object) Hopefully `name` implementation for `null` would enable it for objects from other contexts as well. In addition I have proposed that `name` would just return property if it's not a function: name(object, …rest) = typeof(object[name]) === 'function' ? object[name](…rest) : object[name] Which pot pretty negative feedback: It overlaps and precludes the case where you just want to get the function without calling. As a matter of fact I outlined the primary case where this feature is very helpful in the gist: Watchable.prototype[watchers] = function(target) { return target[watchers] = [] } This enables lazy initialization of private properties that otherwise would have required second private name. While I find this use case quite compelling I see drawbacks as well. Never the less I think that even without the last feature callable private names are pretty compelling. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-06-21 at 11:54 , Irakli Gozalishvili wrote: Hi, Some time ago I tried to get your intention about clojure protocols as I see them as better fit for JS and it's runtime than currently proposed classes. Although I can see that they may have implied too much new semantics. Recently I realized that private name objects can be used to do most of what protocols do with some boilerplate performance penalties: https://gist.github.com/2967124 I was wondering if it's a good idea to adjust private name objects proposal, since IMO it solves some of the ergonomics related issues that would prevent it from taking off: API for calling private named methods is awkward: object[method](foo, bar) With private name methods it's natural: method(object, foo, bar) API for accessing private names is ugly in comparison to normal properties: var data = object[secret] With private methods it can be more natural: var data = secret(object) Private methods can provide not only more natural API (that feels similar to one used today), but there is much more to it, private methods provide semantics very similar to clojure protocols (https://vimeo.com/11236603) that arguably enable interesting ways to do polymorphism (http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post) that IMO fits much better JS runtime than proposed classes. It is also fully harmonious with JS prototypical inheritance. It also solves issues inherent with diversity of community and libraries, as on may define protocol through the set of methods that can be independently implemented for set of libraries used. For example event dispatching protocol may be defined via on, off, emit private methods that later can be implemented without any conflict risks for DOM, jQuery, Backbone, etc... This will allowing one to use same set of privates methods regardless of which library data structure comes from. In a way monkey patching on steroids and conflict risks! Thanks for you time I'm looking forward to your feedback! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
private name methods ?
Hi, Some time ago I tried to get your intention about clojure protocols as I see them as better fit for JS and it's runtime than currently proposed classes. Although I can see that they may have implied too much new semantics. Recently I realized that private name objects can be used to do most of what protocols do with some boilerplate performance penalties: https://gist.github.com/2967124 I was wondering if it's a good idea to adjust private name objects proposal, since IMO it solves some of the ergonomics related issues that would prevent it from taking off: API for calling private named methods is awkward: object[method](foo, bar) With private name methods it's natural: method(object, foo, bar) API for accessing private names is ugly in comparison to normal properties: var data = object[secret] With private methods it can be more natural: var data = secret(object) Private methods can provide not only more natural API (that feels similar to one used today), but there is much more to it, private methods provide semantics very similar to clojure protocols (https://vimeo.com/11236603) that arguably enable interesting ways to do polymorphism (http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post) that IMO fits much better JS runtime than proposed classes. It is also fully harmonious with JS prototypical inheritance. It also solves issues inherent with diversity of community and libraries, as on may define protocol through the set of methods that can be independently implemented for set of libraries used. For example event dispatching protocol may be defined via on, off, emit private methods that later can be implemented without any conflict risks for DOM, jQuery, Backbone, etc... This will allowing one to use same set of privates methods regardless of which library data structure comes from. In a way monkey patching on ste roids an d conflict risks! Thanks for you time I'm looking forward to your feedback! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: private name methods ?
I get few comments on twitter regarding this: So the idea is that a private name object is callable, and name(obj, ...rest) delegates to obj[name](...rest)? Yeah thats is a primary idea: name(object, …rest) = object[name](…rest) Although my hope is that `null` and `undefined` could also be supported in some way. Note that with following will work only if `object` is from the same JS context (iframe): Object.prototype[name] = function() { … } name(object) Hopefully `name` implementation for `null` would enable it for objects from other contexts as well. In addition I have proposed that `name` would just return property if it's not a function: name(object, …rest) = typeof(object[name]) === 'function' ? object[name](…rest) : object[name] Which pot pretty negative feedback: It overlaps and precludes the case where you just want to get the function without calling. As a matter of fact I outlined the primary case where this feature is very helpful in the gist: Watchable.prototype[watchers] = function(target) { return target[watchers] = [] } This enables lazy initialization of private properties that otherwise would have required second private name. While I find this use case quite compelling I see drawbacks as well. Never the less I think that even without the last feature callable private names are pretty compelling. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-06-21 at 11:54 , Irakli Gozalishvili wrote: Hi, Some time ago I tried to get your intention about clojure protocols as I see them as better fit for JS and it's runtime than currently proposed classes. Although I can see that they may have implied too much new semantics. Recently I realized that private name objects can be used to do most of what protocols do with some boilerplate performance penalties: https://gist.github.com/2967124 I was wondering if it's a good idea to adjust private name objects proposal, since IMO it solves some of the ergonomics related issues that would prevent it from taking off: API for calling private named methods is awkward: object[method](foo, bar) With private name methods it's natural: method(object, foo, bar) API for accessing private names is ugly in comparison to normal properties: var data = object[secret] With private methods it can be more natural: var data = secret(object) Private methods can provide not only more natural API (that feels similar to one used today), but there is much more to it, private methods provide semantics very similar to clojure protocols (https://vimeo.com/11236603) that arguably enable interesting ways to do polymorphism (http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post) that IMO fits much better JS runtime than proposed classes. It is also fully harmonious with JS prototypical inheritance. It also solves issues inherent with diversity of community and libraries, as on may define protocol through the set of methods that can be independently implemented for set of libraries used. For example event dispatching protocol may be defined via on, off, emit private methods that later can be implemented without any conflict risks for DOM, jQuery, Backbone, etc... This will allowing one to use same set of privates methods regardless of which library data structure comes from. In a way monkey patching on steroids and conflict risks! Thanks for you time I'm looking forward to your feedback! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Function length
I don't think any library should ever rely on f.length. That's a wrong attitude, there always will be legitimate uses of any feature, otherwise such features are just harmful IMO should be deprecated / removed. It is not a reliable source of information (f might use 'arguments' even when the length is officially 0), and I don't honestly see it being useful for anything but tertiary debugging purposes. In some cases weather function captures `rest` arguments via `arguments` is irrelevant. Like in a case I've pointed out earlier. Library provides arity based dispatch based on f.length, so if you pass `function() { arguments…. }` it will never be called with more than 0 arguments. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Monday, 2012-06-11 at 05:33 , Andreas Rossberg wrote: On 10 June 2012 03:52, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: I just noticed strange behavior in spider monkey implementation of rest arguments: (function(a, b, ...rest) {}).length // = 2 I think ignoring `rest` in length is pretty counter intuitive. For example I have small utility function that I use to dispatch depending on argument length. var sum = dispatcher([ function() { return 0 }, function(x) { return x }, function(x, y) { return x + y }, function(x, y, z) { return Array.prototype.slice.call(arguments, 1).reduce(sum, x) } ]) I don't think any library should ever rely on f.length. It is not a reliable source of information (f might use 'arguments' even when the length is officially 0), and I don't honestly see it being useful for anything but tertiary debugging purposes. /Andreas ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Function length
Sorry for not being clear about this. Here is a simplified example of the implementation: https://gist.github.com/2911817 Also this is just a single particular example, but I expect there to be more. I think what I'm really asking for is a way to know if …rest is being used. Also IMO arrow functions should not have `arguments` at all. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Monday, 2012-06-11 at 11:04 , Allen Wirfs-Brock wrote: On Jun 11, 2012, at 10:56 AM, Irakli Gozalishvili wrote: I don't think any library should ever rely on f.length. That's a wrong attitude, there always will be legitimate uses of any feature, otherwise such features are just harmful IMO should be deprecated / removed. Let me try again. We don't understand your use case. You didn't show us the definition of your dispatch function so we have to guess. Even so, It is hard to imagine a legitimate use with dynamically provided functions, particularly as the length values assigned to the existing built-ins don't follow strict rules. At the very least you need to help us understand why your use case is both reasonable and valid. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Function length
Never the less problem still stands, but maybe there are other ways to solve it. Only solution I'm left with so far is utility function like this: function hasRest(f) { return !!~String(f).split('\n').shift().indexOf('...') } Which is bad, specially toString of function is not guaranteed to return source. Maybe alternative solution could be some standard function / method to test if the function captures ...rest args. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Saturday, 2012-06-09 at 23:54 , Allen Wirfs-Brock wrote: On Jun 9, 2012, at 6:52 PM, Irakli Gozalishvili wrote: I just noticed strange behavior in spider monkey implementation of rest arguments: (function(a, b, ...rest) {}).length // = 2 That answer is consistent with what is specified in the ES6 draft spec. The actual value is specified algorithmically and is summarized by this note: NOTE The ExpectedArgumentCount of a FormalParameterList is the number of FormalParameters to the left of either the rest parameter or the first FormalParameter with an Initialiser. A FormalParameter without an initializer are allowed after the first parameter with an initializer but such parameters are considered to be optional with undefined as their default value. See section 13.1. The draft is based upon the conclusions that were reached when this was last discussed. See the thread starting https://mail.mozilla.org/pipermail/es-discuss/2011-August/016361.html There is no obviously right answer to what should be reported as the length (and it isn't clear whether this property really has any utility). The closest thing we have to legacy precedent are these statement from previous versions of the spec: 15 Every built-in Function object described in this clause—whether as a constructor, an ordinary function, or both—has a length property whose value is an integer. Unless otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the function description, including optional parameters. 15.3.5.1 The value of the length property is an integer that indicates the “typical” number of arguments expected by the function. Note that that the the legacy description is not particularly self consistent and that where a length value is other specified for various built-in functions it tends to follow the 15.3.5.1 rule. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: time to trim mustache
I just want to (re)express my (and many others) concern about new syntax. While Object.extend adds useful feature (Although I think Object.define would be more appropriate name) I don't think new syntax is really necessary. I do think that new syntax needs a lot more justification then new semantics. I also would argue that it's a good idea to alway make syntax changes in a separate iteration from the one where associated semantics have being introduced. That would allow both community and come tee to see these semantics in practice and having more knowledge to decide what syntax sugar would work best, if any new syntax even will turn out to be necessary. One of these things is installing private named properties upon an existing object. As currently specified, those could not be communicated to an extend function via an object literal because we have disallowed any form of refection upon private named properties. Object.extend could not see them on the literal object in order to copy them. Trying to solve this problem by saying that Object.extend has special reflection privileges would violate the encapsulation that the non-relection on private name properties was intended to provided. But many other variations of this would do the job as well without a new syntax: Object.extend(target, privates( name1, value1, name2, value2 )) Anther ES6 specific semantic that has always been part of the mustache proposal is the correct binding of methods with super references. I've described this many times. So I'll just describe it again other than to reinforce that mustache is the great way to dynamically associate super referencing method to an object without running into the pitfalls that arise with the defineMethod alternative. I see how with mustache we can live without defineMethld. But omitting reflection APIs is pretty dangerous path to go with IMO. JS has being great as it was always possible to fix things that were not working for you. I have feeling that providing semantics only through new syntax may take away this great power of JS. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Monday, 2012-06-04 at 09:45 , Brendan Eich wrote: Kevin Smith wrote: Thanks Dave, Of the 3 use cases you mentioned, I think unique names are probably sufficient for 1 and 3. For the second use case (an inaccessible piece of data associated with an object), would not a weak map also be appropriate? No, WeakMaps have two problems we've covered in this list: 1. Less efficient than private names. This matters when you can least afford it, and it matters for private names used to program in the large using objects in JS. WeakMaps require special GC handling and they're an extra object with internal mutable state. Private name objects are flat, frozen, and can be optimized a lot harder. 2. You cannot abstract property access: function get(obj, prop) { return obj[prop]; } works with a private name object referenced by prop. No such abstraction can be done with a weak map. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: arrows and a proposed softCall
I would also like to express that I think = with proposed (bound this) semantics, are great. And I don't think it introduces any new issues it's just a sugar for: function() { /* … */ }.bind(this) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Tuesday, 2012-06-05 at 12:06 , Russell Leggett wrote: On Tue, Jun 5, 2012 at 2:30 PM, Angus Croll anguscr...@gmail.com (mailto:anguscr...@gmail.com) wrote: Yes the thread needs wrapping up. Maybe I can attempt summarize the dilemma - with a question: Is call/apply just a remedy for non-lexical this assignment? Or is it a powerful feature in it own right. I'm with the second camp, but I think I'm in the minority in this list Call/apply are of course powerful features, but they should not be used just for the sake of using them. You know what's cleaner looking than call/apply? Just calling the function directly! I think the bigger, but related question is, When should dynamic |this| be used? Do you think the jQuery style of using the dynamic this in callback is good? Many of us here do not. Dynamic |this| allows for functions to work like methods - it enables mixins and all kinds of meta-programming goodness. However, it can also be abused, and create really funky code that can lead to weird surprises. Maybe I'm just conservative here. I suppose I can see the appeal of not having to add that pesky extra parameter and instead use |this| for whatever arbitrary thing you might want to put there, but it sure seems less readable to me. You might as well just use the arguments object for everything instead having parameter names! Until now, with the addition of bind, and the fat arrow, there were a lot of common cases where you would have to put a callback method back with its original |this| object. That is one use of call/apply, and one that will hopefully need less use. Another nice use of it was to easily delegate by using apply and passing through the arguments object. That will go away with rest parameters. So yeah, we might be seeing less of call/apply with ES6, but I think we're replacing them with better patterns instead of just saying they aren't useful anymore. - Russ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Generators improvement idea
Hi, I have an improvement suggestion for generators. Unless I'm mistaken in spider monkey you `yield` maybe used as a function: function g() { yield(1) yield(2) } for (let $ in g()) console.log($) It would be cool to take this even further and let users give `yield` a context specific name. // yield is passed in function* program(require) { // maybe even alias passed in yield var use = require; var _ = require('underscore') var template = require('asset!./template.html') var data = require('asset!./model.json') document.body.innerHTML = _.template(template, data) } This would loading all assets async but avoid callbacks This is idea came to mind while thinking how SDK APIs that users commonly complain about can be improved (At the moment it web worker like). There are some more examples in the more thoughts section of the following document: https://github.com/mozilla/addon-sdk/wiki/JEP-Content-scripts Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Array.prototype.take
Hi, At the moment Array methods can do almost everything that one can do with plain `for` iteration, only missing piece is `break`. Is there any chance to get something like: array.take(predicate) Although, `take` would be way more useful if array methods chains were applied lazily. So that: array.filter(predicate).map(fn).take(once) would only call `fn` up to a first match. Maybe `Array.prototype.take` is not a best fit, but would be great if we could get at least something to cover lack of `break`. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Array.prototype.take
Well some returns `true` or `false` I was talking more about taking slice of an array. You could obviously do things with an elements in `some` but it feels very wrong to push them into another array. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-05-24 at 18:00 , Axel Rauschmayer wrote: On May 25, 2012, at 2:42 , Irakli Gozalishvili wrote: At the moment Array methods can do almost everything that one can do with plain `for` iteration, only missing piece is `break`. Is there any chance to get something like: array.take(predicate) You can use Array.prototype.some for that purpose: function breakAtEmptyString(strArr) { strArr.some(function (elem) { if (elem.length === 0) { return true; // break } console.log(elem); // implicit: return undefined (interpreted as false) }); } Although, `take` would be way more useful if array methods chains were applied lazily. So that: array.filter(predicate).map(fn).take(once) would only call `fn` up to a first match. Agreed. The ability to chain iterators would be cool. IIRC, there are plans for a module of iterator tools. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) home: rauschma.de (http://rauschma.de) twitter: twitter.com/rauschma (http://twitter.com/rauschma) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: destructuring: as patterns?
On Wednesday, 2012-04-18 at 08:26 , Brendan Eich wrote: We've supported destructuring for years and no one has asked for this. I say YAGNI and when in doubt, leave it out. One can always write two destructuring declarations without much repetition: let {b} = obj; let {x,y} = b; but of course one would just write let {x, y} = obj.b; in that contrived case. Main thing is, not having as-patterns is not a big deal based on experience with JS1.7+ since 2006 in Mozilla code. To be honest I've being running into cases where I wished I could match both parent and children in some way. Also, I think that Herby's version is better in fact I had to learn that it's illegal. Unless it's too much of a deal I'd also like following to work: let { a, b, b: { x, y } } = object; /be Claus Reinke wrote: Looking through the destructuring proposal http://wiki.ecmascript.org/doku.php?id=harmony:destructuring there seems to be no mention of 'as' patterns. In typical pattern matching constructs (SML, Haskell, ..), 'as' patterns allow to name a sub-object while continuing the match for its sub-structures. For instance, with var obj = { a: 0, b: { x: 1, y: 2} }; something like let { b: b as {x,y} } = obj would result in the bindings of b to obj.b, x to obj.b.x, y to obj.b.y. This avoids needless repetition when both a subobject and its components need to be extracted. Without 'as', each such case leads to a separate destructuring assignment let { b } = obj let { b: {x,y} } = obj Shouldn't 'as' patterns be included in destructuring? Or have I missed an equivalent feature? Claus ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: destructuring: as patterns?
Another option that feels intuitive to me is: let { a, b: ({ x, y }) } = object; Parentesis imply that I want both parent and matched children. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-04-18 at 09:01 , Irakli Gozalishvili wrote: On Wednesday, 2012-04-18 at 08:26 , Brendan Eich wrote: We've supported destructuring for years and no one has asked for this. I say YAGNI and when in doubt, leave it out. One can always write two destructuring declarations without much repetition: let {b} = obj; let {x,y} = b; but of course one would just write let {x, y} = obj.b; in that contrived case. Main thing is, not having as-patterns is not a big deal based on experience with JS1.7+ since 2006 in Mozilla code. To be honest I've being running into cases where I wished I could match both parent and children in some way. Also, I think that Herby's version is better in fact I had to learn that it's illegal. Unless it's too much of a deal I'd also like following to work: let { a, b, b: { x, y } } = object; /be Claus Reinke wrote: Looking through the destructuring proposal http://wiki.ecmascript.org/doku.php?id=harmony:destructuring there seems to be no mention of 'as' patterns. In typical pattern matching constructs (SML, Haskell, ..), 'as' patterns allow to name a sub-object while continuing the match for its sub-structures. For instance, with var obj = { a: 0, b: { x: 1, y: 2} }; something like let { b: b as {x,y} } = obj would result in the bindings of b to obj.b, x to obj.b.x, y to obj.b.y. This avoids needless repetition when both a subobject and its components need to be extracted. Without 'as', each such case leads to a separate destructuring assignment let { b } = obj let { b: {x,y} } = obj Shouldn't 'as' patterns be included in destructuring? Or have I missed an equivalent feature? Claus ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: destructuring: as patterns?
On Wednesday, 2012-04-18 at 09:02 , Herby Vojčík wrote: Herby Vojčík wrote: Maybe allowing let {b, b:{x,y}} = obj; would be enough. It sort-of comforms to existing syntax as well as semantics. BTW, if you use var instead of let, if already works out of the box (in FF11 firebug console; just tried), so why include as if it already is there, albeit in different form? OMG, you're right!!! I could swear it did not worked before as I had unsuccessful attempts to use that form. I guess it's ok if Brendan did not knew it either :D Herby ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: callable objects ?
It would be amazing to have clojure like protocols in JS even without `IFn`. I think it's very good feet and very useful in JS where each library has it's own flavored API. I wrote more about it here: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post Also why would callable objects return `function` on `typeof(callable)`. As a matter of fact I think it should be `object` and something new like `Object.isCallable(object)` may be used to check for call-ability. This way old code either will reject non functions or will shim `Object.isCallable` to support new constructs. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-04-11 at 11:54 , Brendan Eich wrote: Michael Fogus wrote: I know some things about ClojureScript and would be happy to answer any direct questions. However, I think its notion (and Clojure proper) is that functions are data are functions is very powerful. It's a great idea (I first met John McCarthy in 1977 when I was 16). Too bad JS was not allowed to be Scheme in the browser. A lot of interesting patterns fall out of this as others have pointed out. I'm ready to jump in with both feet, except for JS's age and the possibility that too much code on the web counts on things like (typeof x == function) = x() works and x.apply is the expected built-in No problem, you say, we can leave typeof alone and add a callable predicate and evangelize that. Ok, provided the callable protocol uses an ES6 private name (think gensym), any public name could be in use and make a false positive when testing callability. So let's use a well-known private (unique, should say) name, e.g. module std { ... export const invokeName = Name.create(invoke); export function callable(v) { if (typeof v == function) return true; if (typeof v == object v != null) return invokeName in v; // could be pickier but let's start here return false; } } // make an object obj be callable: obj[invokeName] = function (...args) { /* ... */ }; Looks ok, ignoring details such as how the client code gets the standard unique name binding (import invokeName from @std or some such). One can't assume apply or call or other Function.prototype heritage is in x just because callable(x) returns true. Callability is wider and weaker than typeof-result function. IIRC, security conscious folks do not want an attacker to be able to make any old object callable. Cc'ing Mark for his thoughts. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: callable objects ?
I have prototyped desugared version of callable objects here: https://gist.github.com/2312621 I could not use short object syntax and unnamed method as proposed in original post, so I used regular object syntax and `new` as method name for unnamed `method`. I tried to illustrates that callable objects may be more elegant alternative to classes specially in combination with `|` (which I expressed as `extend` function). Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Wednesday, 2012-04-04 at 24:56 , David Bruant wrote: Le 04/04/2012 02:41, Irakli Gozalishvili a écrit : On Tuesday, 2012-04-03 at 14:07 , David Bruant wrote: Le 03/04/2012 22:00, Irakli Gozalishvili a écrit : Here is more or less what I have in mind: https://gist.github.com/2295048 // class var Point = { (x, y) { this.getX = { () { return x; } } this.getY = { () { return x; } } } toString() { return '' + this.getX() + ',' + this.getY() + ''; } } Interesting new function syntax. The prototype and function body could even be declared together. What about 'length'? Also such callable objects provide shorter alternative to current function syntax: // shorter than function numbers. filter({ (x) { return x % 2 } }). // maybe single expression can be even shorter like arrow functions ? map({ (x) x * x }). forEach({ (x) { this.add(x) } }, that); +1 Also this would allow interesting APIs similar to those found in clojure: // maps / sets similar like in clojure ? var map = WeakMap(), key = {}, value = {}; map.set(key, value); map(key) // = value So far so good. key(map) // = value This cannot work for backward-compat reasons. In ES1-5, key = {} creates a regular (non-callable) object. Well I did not suggested it should be backwards compatible, also nor classes nor shorter object syntax is backwards compatible. They are to the extent that they throw an error for being invalid syntax in previous version. This is the case for your proposal and that's a good thing since that's the back door to introducing new features. However, proposals should be backward compatible in semantics. In your case: var map = WeakMap(), key = {}, value = {}; map.set(key, value); map(key) // = value key(map) // = value since key is callable, you have (typeof key === 'function') while ES5 requires (typeof key === 'object') for objects that are constructed with '{}'. There is code out there that relies on typeof for argument shifting: 'if the first argument is a function, use that as callback, otherwise, use the second argument (first argument being an option non-callable object)'. There is this pattern all over the place in the mongodb node client as in https://github.com/christkv/node-mongodb-native/blob/master/lib/mongodb/collection.js#L85 In other cases, to pass a handler, some API check if the argument if an object and in that case use the 'handle' property or use the function is what has been passed is callable. So, preserving typeof invariants regarding 'object'/'function' is crucial to backward compatibility. Likewise for arrays. In ES1-5, (typeof [] === 'object') and the suggested semantics of your proposal would break that. As far as I'm concerned, just the object-literal version of function is a brilliant idea, no need for the additional semantics. David ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Protected Protocol
On Tuesday, 2012-04-03 at 01:49 , David Bruant wrote: Le 02/04/2012 17:59, Irakli Gozalishvili a écrit : Hi David, Your protected work reminds me a lot of what we did with `namespcase` module in jetpack: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/api-utils/namespace.html Which I also blogged about some time ago: http://jeditoolkit.com/2012/03/15/namespaces.html#post As soon as I first wrote Protected(this), I thought of Jetpack namespaces :-) I remember that one of your complaints about namespaces was that inheritance was not supported. Do you think there is a workable middleground between namespaces and what I've showed here that would have the benefits of namespaces and inheritance? Adding inheritance support turned out to be pretty easy and there is a patch in a review that would add support to it: https://github.com/mozilla/addon-sdk/pull/375 I have made obvious by juxtaposing both examples that JavaScript requires from the programmer to choose between encapsulation and inheritance. Indeed, as demonstarted above, encapsulation requires a shared scope. I totally agree that with this pain point, but hopefully private names will help this. What drove me to reimplement something like Java's protected is that I fear private names won't be enough. Basically, if an object o is an A and all As are Bs, if you only have private names, then, o's methods inherited from B can access private names related to B. o's methods inherited from A can access private names related to A. However, A methods can access private names related to B only if B shares them (like the secret and age of my example). B can share them globally (in the sense of to anyone, not necessarily as properties of the global object), which effectively makes the private names no longer private, but only unique, or A and B need to share a common scope which, in my opinion, does not scale (it forces A and B to be in the same file which is not always an option if you want to use code written in a library) Still I think that there are other expression problems with classes that could be elegantly solved using clojure like protocols that I have posted other day: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post https://mail.mozilla.org/pipermail/es-discuss/2012-March/021603.html I had completely missed that. Unfortunately I did not got much of a feedback ;) I'll need to watch the video and read more, but that's an interesting idea. Note: That even though both Event and Installable protocols define functions on and off. Also Object implements both still protocols, but there no conflicts arise and functions defined by both protocols can be used without any issues! = This part is rather intriguing. I'm afraid this may lead to confusion. When I write .on, am I installing? adding a listener? Doing both? They are different functions (not the methods). I was asked a similar it in the question and I replied there: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#comment-474857390 https://gist.github.com/2175647 Also, how are name conflits resolved? Regardless of the exact choice, it seems to be implicit and thus certainly confusing. On that aspect, I would tend to prefer traits or a traits-like solution. There are no conflicts that's a whole point :) David ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Protected Protocol
Ah looks like Kris already pointed that out Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Tuesday, 2012-04-03 at 08:00 , Kris Kowal wrote: On Tue, Apr 3, 2012 at 1:49 AM, David Bruant bruan...@gmail.com (mailto:bruan...@gmail.com) wrote: Le 02/04/2012 17:59, Irakli Gozalishvili a écrit : I remember that one of your complaints about namespaces was that inheritance was not supported. Do you think there is a workable middleground between namespaces and what I've showed here that would have the benefits of namespaces and inheritance? Yes, prototypical namespaces are a slight revision away, and I believe Irakli has already integrated that change in Jetpack. https://gist.github.com/2047799 This gist illustrates parallel prototype chains between namespaces, and how a namespace can have a common ancestor prototype for each instance. Kris Kowal ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: callable objects ?
On Tuesday, 2012-04-03 at 14:07 , David Bruant wrote: Le 03/04/2012 22:00, Irakli Gozalishvili a écrit : Here is more or less what I have in mind: https://gist.github.com/2295048 // class var Point = { (x, y) { this.getX = { () { return x; } } this.getY = { () { return x; } } } toString() { return '' + this.getX() + ',' + this.getY() + ''; } } Interesting new function syntax. The prototype and function body could even be declared together. What about 'length'? Also such callable objects provide shorter alternative to current function syntax: // shorter than function numbers. filter({ (x) { return x % 2 } }). // maybe single expression can be even shorter like arrow functions ? map({ (x) x * x }). forEach({ (x) { this.add(x) } }, that); +1 Also this would allow interesting APIs similar to those found in clojure: // maps / sets similar like in clojure ? var map = WeakMap(), key = {}, value = {}; map.set(key, value); map(key) // = value So far so good. key(map) // = value This cannot work for backward-compat reasons. In ES1-5, key = {} creates a regular (non-callable) object. Well I did not suggested it should be backwards compatible, also nor classes nor shorter object syntax is backwards compatible. And maybe built-ins could have it for doing `[]` work: // Maybe even non-magical replacement for `[]` [ 'a', 'b', 'c' ](1) // = 'b' Again, this is a valid ES1-5 expression and throws an error. Arrays and function have diverging opinions on the 'length' property. David Also de-sugared version may be provided (and even prototyped today using __proto__): var Point = Function.create(Object.prototype, function(x, y) { this.getX = function() { return x }; this.getY = function() { return y }; }, { toString: function() { return '' + this.getX() + ',' + this.getY() + '' } }); ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: callable objects ?
On Tuesday, 2012-04-03 at 13:47 , Axel Rauschmayer wrote: I think you should make the distinction between [[Call]] and [[Construct]]. You can do it via (this insntanceof ..) already and dispatch to call / construct if you want. But both would be great to have for objects. It’s probably best to create importable names. Importable names won't allow shorter than function form though, so I think just () {} is better. Then making the `new` operator available to object exemplars becomes indeed simple. For example: // Root object exemplar import Construct from somewhere; let ObjectExemplar = { [Construct](...args) { let inst = Object.create(this); let result = inst.init(...args); return (result === undefined ? inst : result); } } On Apr 3, 2012, at 22:00 , Irakli Gozalishvili wrote: Hi, Please excuse me if this will sound too crazy, but this idea have being growing in my head for so long that I can't stop myself from proposing it here. I have experimented many different ways of doing inheritance in JS: 1. Starting with a simple sugar that reduces machinery involved, similar to backbone.js https://github.com/Gozala/extendables 2. Finishing with class free prototypal inheritance https://github.com/Gozala/selfish I have to say that experience with selfish turned out very interesting, it made things so much simpler no special forms, no twisted relations between constructors and objects, just a plain objects. Most of these things are not obvious until you start using them, but the fact that exemplars (classes) are no different from regular objects in the system makes things much simpler. That being said I have also came to realize that in most of the cases functions as exemplars would be a better feet than objects. As a matter of fact if objects could be made callable I think it could could have replaced most of the things that classes are targeting in more elegant way. Here is more or less what I have in mind: https://gist.github.com/2295048 // class var Point = { (x, y) { this.getX = { () { return x; } } this.getY = { () { return x; } } } toString() { return '' + this.getX() + ',' + this.getY() + ''; } } var a = new Point(0, 0) var b = new Point(1, 7) // Examples from class proposal // extend is like create with a diff that second arg is an object. var SkinnedMesh = Object.extend(THREE.Mesh, { (geometry, materials) { // call the superclass constructor THREE.Mesh.call(this, geometry, materials); // initialize instance properties this.identityMatrix = new THREE.Matrix4(); this.bones = []; this.boneMatrices = []; // ... } update (camera) { THREE.Mesh.update.call(this); } }); Also such callable objects provide shorter alternative to current function syntax: // shorter than function numbers. filter({ (x) { return x % 2 } }). // maybe single expression can be even shorter like arrow functions ? map({ (x) x * x }). forEach({ (x) { this.add(x) } }, that); Also this would allow interesting APIs similar to those found in clojure: // maps / sets similar like in clojure ? var map = WeakMap(), key = {}, value = {}; map.set(key, value); map(key) // = value key(map) // = value And maybe built-ins could have it for doing `[]` work: // Maybe even non-magical replacement for `[]` [ 'a', 'b', 'c' ](1) // = 'b' ({ a: 1, b: 2 })('a') // = 1 ('b')({ a: 1, b: 2 }) // = 2 Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) home: rauschma.de (http://rauschma.de)twitter: twitter.com/rauschma (http://twitter.com/rauschma) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: callable objects ?
Also I just realized that I have not mentioned it but I meant that new Point(0, 0) would do following: var point = Object.create(Point); var value = Function.apply.call(point, arguments); return typeof(value) === 'undefined' ? point : value; Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Tuesday, 2012-04-03 at 17:44 , Irakli Gozalishvili wrote: On Tuesday, 2012-04-03 at 13:47 , Axel Rauschmayer wrote: I think you should make the distinction between [[Call]] and [[Construct]]. You can do it via (this insntanceof ..) already and dispatch to call / construct if you want. But both would be great to have for objects. It’s probably best to create importable names. Importable names won't allow shorter than function form though, so I think just () {} is better. Then making the `new` operator available to object exemplars becomes indeed simple. For example: // Root object exemplar import Construct from somewhere; let ObjectExemplar = { [Construct](...args) { let inst = Object.create(this); let result = inst.init(...args); return (result === undefined ? inst : result); } } On Apr 3, 2012, at 22:00 , Irakli Gozalishvili wrote: Hi, Please excuse me if this will sound too crazy, but this idea have being growing in my head for so long that I can't stop myself from proposing it here. I have experimented many different ways of doing inheritance in JS: 1. Starting with a simple sugar that reduces machinery involved, similar to backbone.js https://github.com/Gozala/extendables 2. Finishing with class free prototypal inheritance https://github.com/Gozala/selfish I have to say that experience with selfish turned out very interesting, it made things so much simpler no special forms, no twisted relations between constructors and objects, just a plain objects. Most of these things are not obvious until you start using them, but the fact that exemplars (classes) are no different from regular objects in the system makes things much simpler. That being said I have also came to realize that in most of the cases functions as exemplars would be a better feet than objects. As a matter of fact if objects could be made callable I think it could could have replaced most of the things that classes are targeting in more elegant way. Here is more or less what I have in mind: https://gist.github.com/2295048 // class var Point = { (x, y) { this.getX = { () { return x; } } this.getY = { () { return x; } } } toString() { return '' + this.getX() + ',' + this.getY() + ''; } } var a = new Point(0, 0) var b = new Point(1, 7) // Examples from class proposal // extend is like create with a diff that second arg is an object. var SkinnedMesh = Object.extend(THREE.Mesh, { (geometry, materials) { // call the superclass constructor THREE.Mesh.call(this, geometry, materials); // initialize instance properties this.identityMatrix = new THREE.Matrix4(); this.bones = []; this.boneMatrices = []; // ... } update (camera) { THREE.Mesh.update.call(this); } }); Also such callable objects provide shorter alternative to current function syntax: // shorter than function numbers. filter({ (x) { return x % 2 } }). // maybe single expression can be even shorter like arrow functions ? map({ (x) x * x }). forEach({ (x) { this.add(x) } }, that); Also this would allow interesting APIs similar to those found in clojure: // maps / sets similar like in clojure ? var map = WeakMap(), key = {}, value = {}; map.set(key, value); map(key) // = value key(map) // = value And maybe built-ins could have it for doing `[]` work: // Maybe even non-magical replacement for `[]` [ 'a', 'b', 'c' ](1) // = 'b' ({ a: 1, b: 2 })('a') // = 1 ('b')({ a: 1, b: 2 }) // = 2 Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) home: rauschma.de (http://rauschma.de)twitter: twitter.com/rauschma (http://twitter.com/rauschma) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Should ... be suffix rather than prefix?
Second feels more intuitive to me Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Tuesday, 2012-04-03 at 13:16 , Mark S. Miller wrote: foo(a, b, ...rest) vs foo(a, b, rest...) Which is clearer? ES6 has currently agreed on the first. English and Scheme agree on the second. This question applies to both http://wiki.ecmascript.org/doku.php?id=harmony:rest_parameters and http://wiki.ecmascript.org/doku.php?id=harmony:spread. -- Cheers, --MarkM ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Protected Protocol
Hi David, Your protected work reminds me a lot of what we did with `namespcase` module in jetpack: https://addons.mozilla.org/en-US/developers/docs/sdk/latest/packages/api-utils/namespace.html Which I also blogged about some time ago: http://jeditoolkit.com/2012/03/15/namespaces.html#post In contrast to this work though namespaces are not class centric and you can use more than one namespace per object. We also use weak maps to implement that. I have made obvious by juxtaposing both examples that JavaScript requires from the programmer to choose between encapsulation and inheritance. Indeed, as demonstarted above, encapsulation requires a shared scope. I totally agree that with this pain point, but hopefully private names will help this. Still I think that there are other expression problems with classes that could be elegantly solved using clojure like protocols that I have posted other day: http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post https://mail.mozilla.org/pipermail/es-discuss/2012-March/021603.html Unfortunately I did not got much of a feedback ;) Cool to see others exploring this area! Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Sunday, 2012-04-01 at 15:28 , David Bruant wrote: Hi, A while ago, I posted a challenge on es-discuss [1]. It was a challenge related to code reuse, modularity and composition. There has been an interesting suggestion [2] [3] which left me a bit unsatisfied since relying on constructor arguments while it may not be always possible to do that. What I describe as the protected protocol is my response to my own challenge. Before explaining it, I'd like to take a step back and discuss about the object oriented properties of JavaScript. Two expected properties of object-oriented languages are encapsulation and inheritance. Encapsulation allows to define objects which can only be interacted with through a given an interface, thus hiding implementation details. In the long run, encapsulation makes the maintenance of components easier since the implementation of an object can be changed without affecting its clients. Encapsulation can be implemented in JavaScript. One usual way is to do as follow: function Storage(){ var array = Array.prototype.slice.call(arguments, 0); return { add: function(e){ array.push(e); }, read: function(i){ return array[+i]; } }; } Here, access to the array is restricted to the interface (add and read methods). Inheritance allows to better reuse code by specializing classes. This can be implemented as well, usually with this pattern: function Storage(){ this.array = Array.prototype.slice.call(arguments, 0); } Storage.prototype = { add: function(e){ this.array.push(e); }, read: function(i){ return this.array[+i]; } }; function StorageWithDeletion(){ Storage.call(this); // equivalent to super; } StorageWithDeletion.prototype = Object.create(Storage.prototype); StorageWithDeletion.prototype.delete = function(i){ delete this.array[+i]; }; To define a storageWithDeletion, there is no need to redefine the add and read method. To extend Storage, StorageWithDeletion here only needs access to the Storage function in the global scope (or Storage module when these will be deployed). This has the nice property that Storage and StorageWithDeletion can be defined in different files since they don't need to share a common function scope I have made obvious by juxtaposing both examples that JavaScript requires from the programmer to choose between encapsulation and inheritance. Indeed, as demonstarted above, encapsulation requires a shared scope. Solutions where Storage and StorageWithDeletion would be defined with a shared scope could be explored, but it would require to define both in the same file, which, I don't want to be a necessity. The trick of the protected protocol is that encapsulation does not really require a shared scope, it's just the most natural way to do it in JavaScript. When a method located in the prototype chain of an object is called, its 'this' references the object from which the method has been called. Programmers have naturally stored the state of an object as own (public) properties of the object as it's the most natural way to bind information to an object. It doesn't have to be this way, though. WeakMaps offer an straightforward API to bind information to an object and it is not necessary to share this WeakMap with the rest of the world. The protected protocol and an example of how to use it can be found at [4] (which is a bit different than a version I tweeted earlier [5]). The most important part in my opinion is that the Person.js and ComputerSavvyPerson.js are defined in 2 different files. The only thing the latter needs is a reference to the constructor it inherits from (here, Person). Things that are expected to be secret can
recursive arrow functions
Today I have noticed one interesting remark from Douglas Crockford on arrow functions: you will need to use the old functions to write self-recursive functions - http://www.yuiblog.com/blog/2012/03/30/what-is-the-meaning-of-this Is that really going to be the case ? I was so much looking forward to [proper tail calls](http://wiki.ecmascript.org/doku.php?id=harmony:proper_tail_calls) and making arrow functions incompatible would be really bad, specially since they seem to be more functiony than current functions. Why not allow naming arrow function or have some syntax for making recursive calls ? Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: arrow function syntax simplified
Few questions on this new arrow functions: let foo = x = x * x 1. What is foo.prototype ? 2. What does new foo(y) does ? 3. Is there going to be equivalent of Function for arrow functions ? 4. Is Function.create(foo) going to work ? 5. Will foo.call, foo.apply pass in the `this` ? Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-03-29 at 07:15 , Brendan Eich wrote: This is all moot now -- see meeting notes and followups. Thin arrow is not going to make it, we want one arrow. The |this| parameter for opting into dynamic rather than default-lexical |this| also died. Method definition shorthand covers the only strong use-case, as Kevin's analysis shows. /be Herby Vojčík wrote: Brendan Eich wrote: Kevin Smith wrote: I hate the CoffeeScript deviation, though. It's just confusing for anyone who ever learned that fat-arrow binds |this| and thin-arrow doesn't. True. On the other hand, all arrows bind |this| is also quite simple and easy to remember. Yes, and I kept the part of the proposal that allows |this| as a leading arrow formal parameter, including with parameter default value. This suggests a slight variation on the strawman, per your suggestion: x - { return this.x; } // lexical this for thin arrow x = this.x // as for fat arrow (this, x) - { return this.x; } // dynamic this, five letter syn-tax (this, x) = this.x // ditto for the expression-body form I like this very much. Clear, orthogonal, readable. It would be nice if this could get through. /be Herby P.S.: Dynamic this no-arg function could also use one-arg shorthand? this = this.x this - { return this.x; } ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
module path resolution
I'v being trying to figure out how ES.next module path resolution would work. Unfortunately proposal is not very clear about it: http://wiki.ecmascript.org/doku.php?id=harmony:modules Here are some of the questions I have: 1. Will html [base element] have a same effect on modules as it has on script tags today ? 2. Are relative paths resolved to a requirer's url, owner html document's urlor baseURI ? If my assumptions are correct this little example is correct: https://github.com/Gozala/packageless/tree/master/examples/es.next/ [base element]:https://developer.mozilla.org/en/HTML/Element/base Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: module path resolution
On Friday, 2012-03-23 at 18:14 , David Herman wrote: On Mar 23, 2012, at 5:05 PM, Irakli Gozalishvili wrote: I'v being trying to figure out how ES.next module path resolution would work. Unfortunately proposal is not very clear about it: http://wiki.ecmascript.org/doku.php?id=harmony:modules There's more info about the resolution semantics on the loaders page: http://wiki.ecmascript.org/doku.php?id=harmony:module_loaders Basically loaders make it possible for programmers to create custom resolution policies. But your question is probably more about what the default policy of the System loader will be on the web. Yeap! First of all, the System loader's baseURL (should it be baseURI? I never understood the difference) would come from the document's URL. So relative would definitely be relative the HTML file. Yeah so by default `document.baseURI` is just a `document.documentURI` or simply URL to the html document. All the relative URLs on that document resolve to the `document.baseURI`. Also, there is an html `base` tag that allows one to set value of `document.baseURI` and there for change relative url resolution. More details can be found in HTML spec: http://www.w3.org/TR/html401/struct/links.html#h-12.4 Here are some of the questions I have: 1. Will html [base element] have a same effect on modules as it has on script tags today ? 2. Are relative paths resolved to a requirer's url, owner html document's urlor baseURI ? If my assumptions are correct this little example is correct: https://github.com/Gozala/packageless/tree/master/examples/es.next/ [base element]:https://developer.mozilla.org/en/HTML/Element/base These are really good points I hadn't thought about. Thanks for bringing it up! I like the idea that ./foo.js forces the loading to be relative to the document, whereas bar/baz.js is interpreted as relative to the base path. I don't have strong feelings myself about what the System loader's policy should be on the web, but I want to make sure our infrastructure is flexible enough to support a) whatever everyone decides is the best policy for the browser, and b) policies like the Node.js / NPM policy. I will have to read up a little more on document.baseURI and base and all that. Let me elaborate a bit on what my intent is: Usually any app / lib code is organized such that third party dependencies are located in an separate directory from an actual program code. This helps to reduce noise for a human eye and also make it easier to work with version control systems, since third party code is commonly not tracked in the same repository. I think it's pretty important to have good support for this. One cleanest way IMO would be to have different resolution login for dependencies: A. ./foo.js ../foo/bar.js B. foo.js, foo/bar.js I'd suggest to resolve A type paths relative to a requirer (ether require module url, or document url). And resolve B type paths relative to a `document.baseURI`. That would allow users to organize codebase as described above and show in the example repo: https://github.com/Gozala/packageless/tree/master/examples/es.next/ Also not that this is somewhat similar to nodejs behavior where `./foo, ../foo/bar` form is used for resolving modules relative to the requirer. While `foo, foo/bar` form is used for installed package dependencies. Unfortunately nodejs policies are bit more complicated than that since `foo` form there won't look in just one `baseURL` instead it does recursive upward search in `node_modules` folders which I don't think is compliant with web. That being said though I think it would map simple cases pretty well. Thanks for the information and ideas! Dave Regards ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
clojure like protocols
I have published a [blog post] about JS [protocol library] that implements clojure like polymorphism, which is interesting as it solves typical [problems with classes]. From my experiment I got a feeling that it may be a much better feet for JS language than classes, so I thought it's worth sharing here. [blog post]:http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post [protocol library]:https://github.com/Gozala/protocol [clojure protocols]:http://clojure.org/Protocols [problems with classes]:https://vimeo.com/11236603 Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: clojure like protocols
Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ On Thursday, 2012-03-22 at 17:09 , Brandon Benvie wrote: Maye I'm crazy but this seems like IDL in a more JavaScript friendly form. Not just WebIDL JavaScript semantics and types friendly, but targeted at implementation using JavaScript which is less friendly and requires Proxy wrappers for many/most things like dom.js does. Which is a good thing and I like this. Maybe I misunderstand your comment but this does not requires Proxy wrappers, in fact it uses just a simple monkey patching of prototypes using non-enumerable, unique names under the hood. With private names it can be improved even further. Or alternatively WeakMaps can be used to implement all of this. On Thu, Mar 22, 2012 at 5:48 PM, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: I have published a [blog post] about JS [protocol library] that implements clojure like polymorphism, which is interesting as it solves typical [problems with classes]. From my experiment I got a feeling that it may be a much better feet for JS language than classes, so I thought it's worth sharing here. [blog post]:http://jeditoolkit.com/2012/03/21/protocol-based-polymorphism.html#post [protocol library]:https://github.com/Gozala/protocol [clojure protocols]:http://clojure.org/Protocols [problems with classes]:https://vimeo.com/11236603 Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Alternative syntax for |
Recently Claus Reinke proposed some alternative that I think feels is so much more natural and simpler than | or beget: Instead of this: foo | { bar: 'bar' } prototype can be a special property: { prototype: foo, bar: 'bar' } simple and easy, of course it can have a different name from `prototype`. Also, this special `prototype` property can be non-configurable, non-writable and non-enumerable falling back to Object.prototype if not provided. Also Object.create(null, { foo: { value: 'foo' } }) will become as simple as { prototype: null, foo: 'foo' }. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Monday, 2011-11-21 at 10:10 , Allen Wirfs-Brock wrote: On Nov 19, 2011, at 11:38 AM, Dean Landolt wrote: On Sat, Nov 19, 2011 at 1:57 PM, Allen Wirfs-Brock al...@wirfs-brock.com (mailto:al...@wirfs-brock.com) wrote: On Nov 15, 2011, at 10:27 PM, Russell Leggett wrote: but given the overall disapproval of the exact syntax of the | operator, I think its at least a little more obvious what is going on. Sorry to be coming late to this thread. I think the above statement is a false characterization to use to start this discussion. There are some who disapprove of | or other similar special character formulation of this operator. There are other who like it a lot. Certainly there isn't overall disapproval. However, we can't really even tell whether there is majority (of what population??) approval or disapproval. At best, all you can legitimately say is that there is not universal approval of the | token. I was under the impression that TC39 generally operates by consensus. As you note, there are some who disapprove -- if some is a non-inconsequential number wouldn't this constitute overall disapproval? It's true that there isn't consensus within TC39 on the | syntax. However, there also isn't consensus on any other specific token or keyword either. At the May TC39 meeting there was consensus on advancing to proposal status the semantic capabilities that were in the enhanced object literal strawman. At the same time it was noted that there wasn't agreement on syntax. Lack of consensus does not mean overall disapproval. It means there isn't overall approval. Further consensus building is still required it might be around the pending proposal or it might be around something else. However, TC39 wan't even mentioned in the statement I took exception to. It seemed to make a broader subjective characterization. FWIW I'm indifferent to the syntax, but it reads just fine to me. Still, I'm sure there's something better lurking. Especially if it's true that since it's infix it could be nearly anything. IMHO begets is pretty winful. I find keywords such as begets a bit more jarring when used as compositional primitives. To me, beget reads fine in isolation such as let bob = tom beget {name: 'Robert'); But when used in combination you get clashes of the underlying natural language meaning of the keywords. Compare let Point = class AbstractPoint begets {... to let Point = class AbstractPoint | {... The first form just doesn't read quite right to me. For the second form, I don't necessarily internally vocalize a natural language word for |. My personal preference is for a special characters based operator based token but it doesn't have to be |. I've frequently suggested : as another alternative. I'm less happy with a keyword operator token but I don't reject that alternative and beget may well be the best of those. However, we have to decide on something or we just won't have this functionality at all. Consensus doesn't mean that everybody likes the solution. It just means that everybody is willing to accept it. What we really need to do is build such a consensus around one of the alternatives. Allen ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: The class operator: a bridge between object and function exemplers
On Monday, 2011-11-14 at 16:50 , David Flanagan wrote: On 11/14/11 4:16 PM, Allen Wirfs-Brock wrote: On Nov 14, 2011, at 3:15 PM, David Flanagan wrote: I have a bad feeling about making 'new' work with both functions and object exemplars. If we can have two different types of classes, we're going to end up using typeof on our class objects to figure out what kind of class they are. If I've got a value C from a library and I think it is an object exemplar, but it is in fact a constructor function, then 'class C' is going to return Function rather than C itself... Well, new'ing object exemplars has always been the central concept of our discussions about them. Essentially it is the self style of object creation and arguably the way the prototypal instantiation is supposed to work. It seems to be what people who really like prototypal inheritance really want to do. Apparently I wasn't paying attention to the early discussions about object exemplars. I've heard the term used, but missed the point about changing the behavior of new. It seems to me people who want to use self-style object creation can use Object.create() and people who want to use JavaScript-style object creation can use new like we've been doing for 15 years. (Just today I wrote a blog post explaining why I'm hoping for classes in ES.next, and included, as part of my argument, the assertion that all the proposals on the table are just syntax sugar without new language semantics. I was wrong about that, I guess!) The magic of what I'm proposing is that you will rarely have to worry about whether a named object abstraction (call it Foo) you get from a library is an object exemplar or a function/class exemplar. Without knowing you can say: new Foo(args) Maybe I'm overreacting, and new semantics can make this all just work. But it seems like a major, major change to the language. and it will work. Without knowing you can do either : let subfoo = Foo| {constructor() {}}; or let subfoo = class Foo| {constructor() {}} //note this parses as: class (Foo| {... }) and things will work. You can even say: let subfoo = Foo| function() {} and the right thinks happen. To me, this seems like the essence of object-oreinted implementation encapsulation. All a client of Foo needs to know is that Foo is an exemplar and hence it can be instantiated (via new) or specialized (via|). It is up to the implementor of Foo to decide how to best express its implementation. They can even change their mind and clients shouldn't care. Do JavaScript programmers want exemplars or do they want classes? Some including me, want exemplars while others want classes. Good thing is that with this proposal both of us will get what we want :) Finally, if you really need to know whether an exemplar is an object exemplar or a function exemplar then typeof Foo is Function seems like a fine way to test it. (I'm really growing to like the is operator...) Object exemplars does not pave the cowpaths for classes: it creates a new path and just smears out the concept of a class into something more broad. I fear it will create confusion rather than provide a terse and declarative surface for those semantics so that programmer intent is expressed instead of the underlying imperative machinery. I look at it from the perspective that we already have at least two cowpaths that meander across each other in ways that make it hard to stay on either one. I'm optimistic that we pave them in such a way that we are really dealing so parallel lanes on the freeway (and this analogy just got totally out of hand). If I may continue the out-of-hand metaphor, I worry that we'll end up with a two lane freeway that is being repaved and has Warning: abrupt edge! signs because one lane is bumpy and 2 inches lower than the other lane. David Allen ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: The class operator: a bridge between object and function exemplers
Sorry I'm so excited about this that I just could not read it all before posting this, my apologies if it's already discussed: On Monday, 2011-11-14 at 17:04 , Allen Wirfs-Brock wrote: UnaryExpression : class UnaryExpression ... The semantics are: 1. if UnaryExpression is undefined or null, return the value of UnaryExpression. 2. Let obj be ToObject(UnaryExpression) 3. Return the result of calling the [[Get]] internal method of obj with argument 'constructor' Interesting, so 'constructor' will inherit from Object.prototype if missing from the exemplar. This means let Point = class { x:0, y,0 }; let p = new Point(1, 2); will result in p being constructed via the equivalent of new Number(1). sh*t! I though I'd had a solution for this, but maybe I don't... If you are really going to define either an object or class exemplar, you really need to define a constructor. The object exemplar case actually works out ok in this case because the inherited constructor is called as a function, not as a constructor. So for let Point = { x: 0, y: 0 }; let p = new Point(1,2); Is pretty much equivalent to: let p = Point | {}; which may not be exactly what the programmer expected but it is a least in the vicinity and yields an object with (inherited) x and y properties. I think this concern could be easily fixed if `class prototype` was equivalent of `Class(prototype)` where implementation of Class is following (BTW I don't propose to use Class function just illustration of what class prototype could be) : function Class(prototype) { function constructor() { Object.hasOwnProperty(prototype, 'constructor') let instance = Object.create(prototype); instance.constructor.apply(instance, arguments); return instance; } constructor.prototype = prototype; return constructor; } As additional benefit this solves issue of shared / frozen constructor properties of the prototype. P.S.: I just yesterday I started experimenting with `Class` function in combination with selfish. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: The class operator: a bridge between object and function exemplers
On Tuesday, 2011-11-15 at 10:58 , David Flanagan wrote: On 11/14/11 5:17 PM, Allen Wirfs-Brock wrote: On Nov 14, 2011, at 4:50 PM, David Flanagan wrote: On 11/14/11 4:16 PM, Allen Wirfs-Brock wrote: On Nov 14, 2011, at 3:15 PM, David Flanagan wrote: I have a bad feeling about making 'new' work with both functions and object exemplars. If we can have two different types of classes, we're going to end up using typeof on our class objects to figure out what kind of class they are. If I've got a value C from a library and I think it is an object exemplar, but it is in fact a constructor function, then 'class C' is going to return Function rather than C itself... Well, new'ing object exemplars has always been the central concept of our discussions about them. Essentially it is the self style of object creation and arguably the way the prototypal instantiation is supposed to work. It seems to be what people who really like prototypal inheritance really want to do. Apparently I wasn't paying attention to the early discussions about object exemplars. I've heard the term used, but missed the point about changing the behavior of new. It seems to me people who want to use self-style object creation can use Object.create() and people who want to use JavaScript-style object creation can use new like we've been doing for 15 years. (Just today I wrote a blog post explaining why I'm hoping for classes in ES.next, and included, as part of my argument, the assertion that all the proposals on the table are just syntax sugar without new language semantics. I was wrong about that, I guess!) Object create doesn't do the job because it doesn't provide for calling an initialize methods (turns out to be a very important part of the self-style). Its not like there's a large community of self programmers out there who are migrating to JavaScript... It seems to me that if you like the object exemplar style, then you don't want to be using the new operator and constructor functions (or things that appear to be constructors because they're used with new). Instead you want to define factory functions that use Object.create(): But making it possible to reuse libraries that are written either object or class exemplar supporters is a huge win to me! function Range(from, to) { return Object.create(Range.methods, { from: { value: from, enumerable: true }, to: { value: from, enumerable: true} }); } Range.methods = { includes: function(x) { return this.from = x x = this.to; } }; Range(1,3).includes(2); // = true Do JavaScript programmers want exemplars or do they want classes? They seem to be split. Some vocally ask for better support for prototypal inheritance other vocally ask for classes. Irakli has self-identified in this thread as wanting object exemplars but he has also defined a simple and useful Class() function for working with them. I suspect that part of the appeal of object exemplars is that it is easier to write support functions like Class() for working with them. That is: we can make the proponents of object exemplars happy with good library support. But for classes, we need language support... I think what everybody is asking for is a better way to created named object abstractions. The term exemplar is just one that I introduced into the discussion to make it easier to talk about the different kinds of entities you might apply such names to. In some language you name a class declaration, in others you name a prototypal instance, in JS you have historically named a function. Exemplar was intended to be a generic for such named object abstractions. An object exemplar is a self style prototype, a class exemplar is the sort of thing you find in languages llke Java. A function exemplar is a JS constructor, Are there existing languages that support more than one kind of exemplar at the language level? It seems to me that JS is stuck with function exemplars, and we should work to make those better, not add complexity to the language by adding support for another style of exemplar. David ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist (why) classes ?
On Monday, 2011-11-14 at 10:42 , Rick Waldron wrote: The tests I wrote for Selfish illustrate that it also has this behaviour, but is more deceiving because you think you're getting new instances. Hey Rick, I'd be interested to see those tests since it's not supposed to mutate any arguments passed to it, and if that's a case it's a bug and I'd like to fix it. Thanks! ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist (why) classes ?
I think this discussion drifted into slightly diff direction. What I intended to say was that today all major frameworks use same patter to do subclassing. They all implement different APIs to do the following: function subclass() { // init …. } subclass.prototype = Object.create(superclass) Object.defineProperty(subclass.prototype, 'constructor', { value: subclass }) subclass.prototype.method = function() { //... } Object.extend used in my gist is BTW same as backbone's .extend and is just a shortcut of the code above: var subclass = superclass.extend({ initialize: function() { // init ... }, method: function() { // …. } }) What I'm asking for is a standard function, no matter weather it's `Object.extend` or something else that makes it simple to do subclassing. Also lisper in me thinks that `Object.extend` method is better than dedicated class syntax cause it keeps language concise. In addition I think that if `Object.extend` will turn out to be broken it will be easier (not to say easy) to fix (`Object.extend = … `) then fixing `class Foo extends Bar`. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Sunday, 2011-11-13 at 13:21 , Brendan Eich wrote: On Nov 13, 2011, at 11:28 AM, John J Barton wrote: On Sun, Nov 13, 2011 at 9:34 AM, Brendan Eich bren...@mozilla.com (mailto:bren...@mozilla.com) wrote: On Nov 13, 2011, at 9:30 AM, Brendan Eich wrote: The hard cases include: 1. Closures. 2. Proxies. 3. Private names. 4. Internal hidden state. 5. Side-table entries mapped to the object's identity. In the case of objects implemented by C++ or whatever the host implementation language might be, the internal or side-table state may not even be representable in JS, even in strings (do not want raw pointers, or machine addresses however obfuscated, to leak to an attacker). I think we are on the wrong path here. I guess we followed: a standard extend() needs a copy-ish operation; a copyish operation is like cloning; cloning is hard; OMG. That's not what happened. Some people are happy with shallow copy of properties available to ES5 reflection, or even a for-in loop. Others (Rick?) want deep, at least as an option. Deep could skip any private/internal/etc. properties, for sure. But deep tends to get into trouble because if you don't stay shallow, you run immediately into item 1: Closures. How would those be deeply copied, including their lexical environments? But let's back up. We are looking for one or a few operations such that: var a = op(b,c,d,...); creates a useful result when we use |a| and we are using existing JS libraries for guidance. By definition there are no show stoppers here. I agree, other than inability to agree on what to standardize. We are creating new objects from existing objects using operations available to JS devs, but in standard and recommended way. The only two things can stop us from being successful: irreconcilable differences and inertia. Ok, but this is all meta-pep-talk. What should the reconcilable standard be? /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist (why) classes ?
On Friday, 2011-11-11 at 18:38 , Brendan Eich wrote: Having written all this, I will repeat that I like your selfish work and the exemplar idea Thanks, that's really encouraging! ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: WeakMaps question ?
I really need to know why WeakMaps don't accept primitives as keys, can anyone please reply ? Thanks! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Thursday, 2011-11-10 at 10:31 , Irakli Gozalishvili wrote: Hi, I was wondering what is a reason for disallowing non-object values as keys in WeakMaps ? Also, I think I have a pretty good use case for primitive keys: Worker process sends messages to the (main) UI process, to initiate UI notification. If user clicks that notification main process will worker know that given notification was clicked: (function(exports) { let id = 0 let listeners = WeakMap() exports.notify = function notify({ onClick, message }) { if (onClick) listeners.set(++id, onClick) self.postMessage({ id: id, message: message }) } self.onmessage = function({ id }) { let listener = listeners.get(id) if (listener) listener() } })(this) Is my use case invalid ? At the moment I use custom map implementation with a limited size, once map hits the limit oldest entries will be removed. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Minimalist (why) classes ?
Hi, I have posted this to the long thread of Minimalist Classes, but since I have not got any response, I assume it got lost into a long discussion. So I thought I'll give it another try on fresh thread. I do really liked direction that Jeremy tried to push classes to, but still I don't understand why do we need to introduce new syntax to the language. From what I can tell, lack of classes or special syntax for creating ones, is not a problem. Problem is amount of ceremony one needs to perform inherit or subclass if you like. Also, I think we don't need new `class` expression to solve actual problems we have, simple function will do the job perfectly here, also it will add zero learning curve! I forked Jeremy's proposal and modified it to ilustrate how existing subclassing problems can be solved without introducing new constructs to the language or adding more verbosity. Please also note that there is nothing new here, lot's of frameworks do this already (hide prototype machinery), but each does it with it's own flavored API which is IMO another problem that standardization should solve. The classes problem is very similar to `Function.prototype.bind` that ES5 solved greatly, why not do the same for classes ? https://gist.github.com/1355701 In addition I tried to address few other concerns I had with a proposal: - `constructor` property as initializer is poor choice raising many questions (what will be prototype of constructor property if it's used in more then one class, if it's frozen etc). - Some people in the community would love to have frozen classes others value flexibility, simple functions make it easy to build first out of second without becoming a second class citizen. Please note, that I intentionally omitted `super` as it's separate problem that is / must be discussed in the separate thread / proposal. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: WeakMaps question ?
I think what I need is a map with primitive keys and non-null object values, entries of which can be removed GC-ied if values are no longer referenced. If I understand Map / Set / WeakMap proposals non of them can be used to solve this issue or do I miss something ? Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Friday, 2011-11-11 at 15:39 , Oliver Hunt wrote: A weak map can only remove an entry if both the key and value have died, in many ES implementations a number of the primitives are not gc allocated and so can never die, or are cached globally so have lifetime unrelated to any given program. The net effect of allowing such primitive values to be used as keys would be to make the map strong and the associated values would not be able to be collected. --Oliver On Nov 11, 2011, at 3:28 PM, Irakli Gozalishvili wrote: I really need to know why WeakMaps don't accept primitives as keys, can anyone please reply ? Thanks! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Thursday, 2011-11-10 at 10:31 , Irakli Gozalishvili wrote: Hi, I was wondering what is a reason for disallowing non-object values as keys in WeakMaps ? Also, I think I have a pretty good use case for primitive keys: Worker process sends messages to the (main) UI process, to initiate UI notification. If user clicks that notification main process will worker know that given notification was clicked: (function(exports) { let id = 0 let listeners = WeakMap() exports.notify = function notify({ onClick, message }) { if (onClick) listeners.set(++id, onClick) self.postMessage({ id: id, message: message }) } self.onmessage = function({ id }) { let listener = listeners.get(id) if (listener) listener() } })(this) Is my use case invalid ? At the moment I use custom map implementation with a limited size, once map hits the limit oldest entries will be removed. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist (why) classes ?
Thats exact port of proposal that Jeremy wrote here: https://gist.github.com/1329619 I could write add examples from the classes proposal if that wolud help: http://wiki.ecmascript.org/doku.php?id=harmony:classes Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Friday, 2011-11-11 at 16:05 , John J Barton wrote: On Fri, Nov 11, 2011 at 3:47 PM, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: Hi, I have posted this to the long thread of Minimalist Classes, but since I have not got any response, I assume it got lost into a long discussion. So I thought I'll give it another try on fresh thread. I do really liked direction that Jeremy tried to push classes to, but still I don't understand why do we need to introduce new syntax to the language. From what I can tell, lack of classes or special syntax for creating ones, is not a problem. Problem is amount of ceremony one needs to perform inherit or subclass if you like. Also, I think we don't need new `class` expression to solve actual problems we have, simple function will do the job perfectly here, also it will add zero learning curve! I forked Jeremy's proposal and modified it to ilustrate how existing subclassing problems can be solved without introducing new constructs to the language or adding more verbosity. Please also note that there is nothing new here, lot's of frameworks do this already (hide prototype machinery), but each does it with it's own flavored API which is IMO another problem that standardization should solve. The classes problem is very similar to `Function.prototype.bind` that ES5 solved greatly, why not do the same for classes ? https://gist.github.com/1355701 Just FYI, I found the listing confusing, since the examples seem unrelated to each other and there is no reference to the corresponding 'class' proposal. jjb ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist (why) classes ?
What I'm suggesting is to sugar current patterns, without adding new syntax similar to how Funciton.prototype.bind was added. And maybe in next iteration add special syntax if it still we be wanted. It's just so much easier to fix `Object.extend` if it will end up to be a wrong fit than change a special class syntax. BTW I have updated examples to illustrate exactly what is problematic requires sugar https://gist.github.com/1355701 Class syntax is wanted to avoid some method calling boilerplate that's more verbose, In my examples it actually takes same amount of chars: class Foo extends Bar {} VS var Bar = Foo.extend({}) arguably easier to get wrong, and harder to analyze and optimize. That's it. Arguably indeed, IMO increasing surface of language makes surface of things that can be made wrong bigger, increasing probability of making things wrong. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Friday, 2011-11-11 at 16:31 , Brendan Eich wrote: On Nov 11, 2011, at 4:09 PM, Irakli Gozalishvili wrote: Thats exact port of proposal that Jeremy wrote here: https://gist.github.com/1329619 I could write add examples from the classes proposal if that wolud help: http://wiki.ecmascript.org/doku.php?id=harmony:classes Maybe, but I think that you'd be beating a dead horse. Class syntax is wanted to avoid some method calling boilerplate that's more verbose, arguably easier to get wrong, and harder to analyze and optimize. That's it. Hence, classes as sugar. If you find existing JS sweet enough, you won't want classes. /be Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Friday, 2011-11-11 at 16:05 , John J Barton wrote: On Fri, Nov 11, 2011 at 3:47 PM, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: Hi, I have posted this to the long thread of Minimalist Classes, but since I have not got any response, I assume it got lost into a long discussion. So I thought I'll give it another try on fresh thread. I do really liked direction that Jeremy tried to push classes to, but still I don't understand why do we need to introduce new syntax to the language. From what I can tell, lack of classes or special syntax for creating ones, is not a problem. Problem is amount of ceremony one needs to perform inherit or subclass if you like. Also, I think we don't need new `class` expression to solve actual problems we have, simple function will do the job perfectly here, also it will add zero learning curve! I forked Jeremy's proposal and modified it to ilustrate how existing subclassing problems can be solved without introducing new constructs to the language or adding more verbosity. Please also note that there is nothing new here, lot's of frameworks do this already (hide prototype machinery), but each does it with it's own flavored API which is IMO another problem that standardization should solve. The classes problem is very similar to `Function.prototype.bind` that ES5 solved greatly, why not do the same for classes ? https://gist.github.com/1355701 Just FYI, I found the listing confusing, since the examples seem unrelated to each other and there is no reference to the corresponding 'class' proposal. jjb ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Minimalist Classes
Hi, Sorry have not had a chance to reply on this thread earlier. I do really like the direction that Jeremy pushes to, but still I don't understand why do we need to introduce new syntax to the language. I think `class` expression is completely unnecessary, why not a function ? I forked Jeremy's proposal and modified it so that it preserves it's simplicity without introducing any new syntax to the language: https://gist.github.com/1355701 In addition I changed few things that was raising additional questions: - `constructor` property as initializer (what if constructor is shared, frozen etc). I also intentionally omitted `super` as it's separate topic. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Thursday, 2011-11-03 at 11:33 , Brendan Eich wrote: On Nov 3, 2011, at 6:53 AM, Matthew Tretter wrote: Sorry, I'll try to be more clear. What's super-intuitive isn't *that* you use the form class name expr, it's how you interact with that form once you know what it does. The reason is self-evident—people know how to work with object literals and functions. Then we are not talking about the same thing. Class syntax of the form class C {...} where the {...} is an extension of ES3-5 ObjectLiteral syntax is fine, we're aligned on that (for the moment). The particular form from Jeremy's gist: // Note that the right-hand side of a class definition is just an expression, // an object literal is not required. You can be fully dynamic when creating a // class: class Student objectContainingStudentProperties line 59 on at https://gist.github.com/1329619 is what is at issue. This is not true of the Leather form which, like I said, would probably inspire a lot of run(a){…} attempts at function definitions in non-class contexts. Different topic yet again, but ok: method definition syntax was already proposed a while ago by Allen, and promoted to Harmony for ES.next. It may cause some Dart-like 'function'-lacking misplaced method definition attempts, indeed. We should see how big a problem this is in practice. I doubt it'll be more than a speed-bump for some, but if it is, we can adapt. Not that that alone is enough to disqualify it, but it's something that should be taken into consideration. Agreed. Off the top of my head, one use-case would be Python-like method decorators: class Runner { run: require_auth(function(a) { }) } Another would be the dynamic definition of methods: class Runner { run: (function() { return someFeatureIsSupported ? feature : polyfill; })() } These are still legal, with class body built on extended object literals. Why did you think these would be verboten? It's one thing to say these should work. It's another to insist that the long-hand should be the only way. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Enums?
On Monday, 2011-10-03 at 19:17 , David Herman wrote: A couple reactions: - strings are already interned in current engines for symbol-like performance; there's no need to introduce symbols into the language Assuming that's about Ruby like [symbols](http://www.ruby-doc.org/core-1.9.2/Symbol.html) or Clojure like [keywords](http://clojure.org/data_structures#toc8). While they are not much different from strings I really miss them in JS. Also I think clojure uses them in a very interesting way: (use 'clojure.contrib.shell-out :as shell :reload) or even more intensive (ns com.my-company.clojure.examples.my-utils (:import java.util.Date) (:use [clojure.contrib.def :only (defvar-)]) (:require [clojure.contrib.shell-out :as shell])) Problem with strings is that it's not always obvious weather it's intended argument to the function or a flag. - private names are overkill for most uses of enums; just use string literals - in SpiderMonkey I think you get better performance if your switch cases use known constants; for example: const RED = red, GREEN = green, BLUE = blue; ... switch (color) { case RED: ... case GREEN: ... case BLUE: ... } - with modules, you would be able to define these consts and share them modularly (currently in SpiderMonkey the only way to share these definitions across modules as consts is either to make them global or to share an eval-able string that each module can locally eval as a const declaration -- blech) Dave On Sep 30, 2011, at 7:13 PM, Axel Rauschmayer wrote: One language feature from JavaScript that I miss are enums. Would it make sense to have something similar for ECMAScript, e.g. via Lisp-style/Smalltalk-style symbols plus type inference? If yes, has this been discussed already? I feel strange when I simulate symbols with strings. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) twitter.com/rauschma (http://twitter.com/rauschma) home: rauschma.de (http://rauschma.de) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: new Object
I think we should just forget about new keyword, prototype property all togather and move towards something more simple: var proto = { method: function() { }, new: function() { var self = Object.create(this); this.initialize.apply(self, arguments); return self; }, initialize: function(someValue) { this.things = someValue } } var o = proto.new(someValue); Of course with a help of library that would not require as much boilerplate: https://github.com/Gozala/selfish Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Tuesday, 2011-10-11 at 20:53 , Jake Verbaten wrote: is there any kind of proposal for syntax that is like : var proto = { method: function() { }, constructor: function(someValue) { this.things = someValue } }; var o = new proto(someValue); Object.getPrototype(o) === proto; // true basically defining how `new` operates on an object (that is to represent the prototype). It is basically equivelant to var Constructor = function () { ... } constructor.prototype = { method: ... constructor: Constructor } var o = new Constructor(someValue); To me personally the whole duplication the Constructor on Constructor.prototype.constructor and having .prototype on a function is less elegant. Initial concerns with such syntax : - new { ... }(parameters) may be difficult to parse - new protoObj.call(...) is not going to work (protoObj does not have Function.prototype in it's prototype chain), should it work? - new protoObj(); should probably throw an error if protoObj.constructor is not defined. - should we invoke a constructor property of a protoObj that is not it's own property - the new operator is confusing enough as it is Advantages: - this syntax would map more closely with the proposed declarative class syntax. So class could just be a sugar for generating objects you can invoke with new. - For any well formed existing code (where .prototype.constructor is set) new existingObject() should generate a new object with existingobject as it's prototype and having called the nearest constructor property - constructor property is optional so new someObject is just sugar for Object.create(someObject) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: new Object
Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Monday, 2011-10-17 at 11:16 , Jake Verbaten wrote: I do the same with Object.prototype.new = function () { var o = Object.create(this); o.constructor o.constructor.apply(o, arguments); return o; } However rather then calling proto.new(); I would like var o = new proto(); May I ask why (less syntax in language is better no) ? and o instanceof proto to work You have proto.isPrototypeOf(o) instead. On Oct 17, 2011 9:17 AM, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: I think we should just forget about new keyword, prototype property all togather and move towards something more simple: var proto = { method: function() { }, new: function() { var self = Object.create(this); this.initialize.apply(self, arguments); return self; }, initialize: function(someValue) { this.things = someValue } } var o = proto.new(someValue); Of course with a help of library that would not require as much boilerplate: https://github.com/Gozala/selfish Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Tuesday, 2011-10-11 at 20:53 , Jake Verbaten wrote: is there any kind of proposal for syntax that is like : var proto = {method: function(... ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
__doc__ for functions, classes, objects etc.
I also prototyped this idea mainly for node. Also, I figured out a hack with a label, that make it work for spidermonkey. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Thursday, 2011-09-01 at 20:28 , Dmitry A. Soshnikov wrote: On 31.08.2011 18:38, Allen Wirfs-Brock wrote: On Aug 31, 2011, at 1:57 AM, Dmitry A. Soshnikov wrote: On 30.08.2011 20:39, Allen Wirfs-Brock wrote: On Aug 30, 2011, at 12:39 AM, Dmitry A. Soshnikov wrote: OK, let's up the topic. Seems there are no technical issues in the proposed thing -- we can simply either accept it or not. The question is whether it's needed and sound proposal and the feature to have in ECMAScript. There certainly are technical issues. To start, by making this part of the core language you would be defining a feature that can be used by any application code. For example, a program might choose to encode essential runtime metadata as its documentation. Because of that possibility, the [[Documentation]] information must always be available at runtime. Minimizers or obfuscators could not remote documentation comments because of the possibility of breaking such programs. Sure, though I don't think that application level code have to be dependent in logic on documentation string. The doc-string is just the _addition for debug_. No more, no less. It's when you use a new lib (my example with Redis's `get` method which should accept callback), you just get this help directly from here without going to some websites (which can even be down for this time) and solve the problems much faster. And for minified scripts, I think the option Remove doc-comments is the case. When designing language features, a designer always has some specific use cases in mind. But that doesn't restrict users of the language from discovering other use cases. Once a feature is incorporated into a language, implementation have to support all possible use cases, not just the original intended use case. That's why it is important for language designer to think broadly about all conceivable uses and feature interaction when extending a language. Sure, no application is required to have logic dependencies upon the content of a documentation string but once they exist any application could have such dependencies. As a language designers you have to think about the implications of such usages. It isn't good enough to just say that wasn't the intended use of the feature. Yes, of course it's true, we have to consider the most hardcore use-cases of our programs. Well, then I have to think on it, but the first thing which comes in mind -- already mentioned Remove doc-comments option for minifiers, i.e. a user himself is responsible for this action. Moreover, minification is again mostly for browser-scripting, where this help(...) functionality isn't so required as it is for the server programming in the console. And for the later case I wrote a simple version of such a pre-processor: https://gist.github.com/1186853 Simple example: /** * sum * @param {Number} x * @param {Number} y * The function of summation. */ function sum(x, y) { return x + y; } /** * multSum * @param {Number} x * @param {Number} y * @param {String} value * The function of calculation. */ function calculate(x, y, value) { // comment print(value + : + sum(x, y)); } // -- Test documentation -- // Result: // Help on sum function: // // /** // * sum // * @param {Number} x // * @param {Number} y // * The function of summation. // */ help(sum); // Help on calculate function: // // /** // * multSum // * @param {Number} x // * @param {Number} y // * @param {String} value // * The function of calculation. // */ help(calculate); // -- Test guards -- sum(1, 2); // 3, OK calculate(1, 2, value); // value: 3 sum(1, 2); // TypeError: y must be a number calculate(1, 2, 4); // TypeError: value must be a string Dmitry. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: __doc__ for functions, classes, objects etc.
On Saturday, 2011-09-03 at 24:55 , Oliver Hunt wrote: On Sep 2, 2011, at 3:41 PM, Brendan Eich wrote: On Sep 2, 2011, at 3:29 PM, Irakli Gozalishvili wrote: On Friday, 2011-09-02 at 22:28 , Brendan Eich wrote: Can you show your label hack for SpiderMonkey to es-discuss? Ahh sorry I did not realized I forgot to post link: https://github.com/Gozala/doc Cool! Permit me to cite some of your README content to help promote to those who did not click ;-) -- here it is: var doc = require('doc').doc doc(doc) // Prints following output: /* function doc(source) { ... } --- Prints documentanion of the given function */ // You can also document your own functions: function compose() { doc: Returns the composition of a list of functions, where each function | consumes the return value of the function that follows. In math | terms, composing the functions `f()`, `g()`, and `h()` produces | `f(g(h()))`. | Usage: | var greet = function(name) { return 'hi: ' + name } | var exclaim = function(statement) { return statement + '!' } | var welcome = compose(exclaim, greet) | welcome('moe') | // 'hi: moe!' Function.toString isn't standardised, and I recall that in the past SM did elide dead code, multiple engines reformat code, so in general this doesnt seem reliable at a library level. Yeap toString is not reliable, but hey it works just fine on most engines I know ;) Also SM strips out dec code that's why I use label hack so that it keeps it :) It also doesn't work for builtin functions, and I feel we'd want a solution that allows documentation for builtin functions as well. In fact `doc` function will work with built-ins just fine, even though output is not that useful: doc(Array.prototype.slice) function slice($1, $2) { ... } From the pov of runtime identification, we'd be in the odd position of having to try and identify valid code as being documentation. This shouldn't be taken as support for this idea (documentation as part of the language) as I feel that this is the type of feature i'd associate with the development environment rather than part of the language. --Oliver ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Subject: Re: Harmony - proxies | asynchronous
In case someone is interested I've experimented with proxy sugared promises (it was long time ago some few things might require updates): https://github.com/Gozala/meta-promise Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Monday, 2011-09-05 at 23:37 , Dmitry Soshnikov wrote: On 03.09.2011 1:26, John J Barton wrote: I'm pretty puzzled by this discussion and I'm guessing other folks might be puzzled as well. Since I understood node fibers as thread for Node, the discussion I read is: /be: You can have threads! Mikeal: We don't want threads! If I'm on the right track, then I should understand how this relates to proxies. But I don't. Any hints? Don't be worry :) the topic is a little bit changed. Initially it was asked how to provide asynchronous property readings (proxy's `get` trap, or a simple accessor's get which call some deferred action) in the syncronious view. And consuming generators (being a technique of implementation of cooperative processes) allow to do this, since can suspend a process and resume it from the next line, i.e. representing asynchronous in syncronious view. But, that's said, even more elegant of such a technique would be either syntactic transformation at compilation level, or creation of implicit task-wrapper with a sugar for `yield` in this case. Regarding not using `yield` for improving asynchronous programming -- I also didn't understand the reasons. Because currently programming in Erlang (which have the same green thread which are managed by an _implicit_ scheduler) I can say that Node.js's spagetty-code with nested callbacks just, sorry, sucks in comparison with Erlang's which is also asynchronous, but allows to write it all in the synchronous manner. Though, the topic is not about Erlang... Dmitry. ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: prototype focus
I absolutely agree with Alex and have few other points: 1. Does this code looks familiar ? function Foo(options) { } Foo.prototype.do_foo_job = function() { ... } function Bar(options) { if (!(this instanceof Bar)) return this new Bar(options); Foo.apply(this, arguments); } Bar.prototype.do_bar_job = function() { } With focus on prototype this is so much simpler: var Foo = Object.extend({ initialize: function(options) { ... }, do_foo_job: function() { ... } }) On Friday, 2011-07-01 at 11:10 , Axel Rauschmayer wrote: I don't think JavaScript has ever been far from its prototype roots especially if the programmer shifts to thinking about a prototype object instead of thinking about a functions prototype property. That is basically the point that the proposal tries to make. Have you taken a look at the library code? It is very short and not a radical overhaul. http://dl.2ality.com/dl/2011/06/Proto.js Note how below, there is always an extra prototype in there with constructor functions. Super-calls (there will be syntactic sugar for this): - Constructor functions: Superclass.prototype.foo.call(this) - PAC: Superclass.foo.call(this) Subclassing: - Constructor functions: Subclass.prototype = Object.create(Superclass.prototype) - PAC: let Subclass = Object.create(Superclass) Instanceof (internally): - Constructor functions: o instanceof C === C.prototype.isPrototypeOf(o) - PAC: o instanceof C === C.isPrototypeOf(o) Problems that both prototypes-as-classes (PAC) and class literals (CL) are trying to solve are: - Subclassing is hard and not directly supported by the language: connecting prototypes, chaining constructors, super-references. Object.getPrototypeOf(this).foo.call(this) is pretty long. See above. It seems to me that perhaps the PaC drifted too far or perhaps started too far from what JavaScript has already. If the idea is to shift the focus more towards prototypes, then starting from something like what I've written and adding super syntax would be more consistent with what JavaScript already has. “too far from what JavaScript has already” is very vague. How so? With class literals, your code will look like PAC, anyway. Have you taken a look at Sect. 3? Do you agree that the mentioned conceptual simplifications hold? http://www.2ality.com/2011/06/prototypes-as-classes.html#3 I find Brendan’s anti-PAC argument much more convincing: that all people might find it more natural to think in terms of constructors than in terms of prototypes. If that is the case then PAC would be a bad idea. The other convincing anti-PAC argument is that it is a bad idea to have two class mechanisms. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) twitter.com/rauschma (http://twitter.com/rauschma) home: rauschma.de (http://rauschma.de) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: prototype focus
Sorry I did not intended to send email yet: So here is my points: 1. Does this looks familiar (version with syntax highlighting https://gist.github.com/1058534) function Foo(options) { } Foo.prototype.do_foo_job = function() { ... } function Bar(options) { if (!(this instanceof Bar)) return this new Bar(options); Foo.apply(this, arguments); } Bar.prototype = Object.create(Foo.prototype); Bar.prototype.do_bar_job = function() { }; With focus on prototypes it's as simple as this: var Foo = Object.extend({ initialize: function(options) { ... }, do_foo_job: function() { ... } }) var Bar = Foo.extend({ do_bar_job: function() { ... } }) Why should not be I able to reuse initialization function, or why do I have to create constructor function for all classes / subclasses ? 2. With a constructor focused classes you end up maintaing two sets of properties: 1. prototype properties and 2. (java static like) constructor properties, which adds complexity requires dedicated syntax in declarative classes syntax. 3. It could be my personal, internal conflict, but I seriously can't see any reason for `constructor` to be a special among all other methods, by having privilege to hold a reference to a prototype object (I don't even mention that this reference is circular by default). Overall `prototype` property feels like hack to emulate Java like classes. 4. With focus on prototypes there is potential to further reduce language syntax (hopefully new, instanceof will die off) instead of cluttering even further. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Friday, 2011-07-01 at 15:19 , Irakli Gozalishvili wrote: I absolutely agree with Alex and have few other points: 1. Does this code looks familiar ? function Foo(options) { } Foo.prototype.do_foo_job = function() { ... } function Bar(options) { if (!(this instanceof Bar)) return this new Bar(options); Foo.apply(this, arguments); } Bar.prototype.do_bar_job = function() { } With focus on prototype this is so much simpler: var Foo = Object.extend({ initialize: function(options) { ... }, do_foo_job: function() { ... } }) On Friday, 2011-07-01 at 11:10 , Axel Rauschmayer wrote: I don't think JavaScript has ever been far from its prototype roots especially if the programmer shifts to thinking about a prototype object instead of thinking about a functions prototype property. That is basically the point that the proposal tries to make. Have you taken a look at the library code? It is very short and not a radical overhaul. http://dl.2ality.com/dl/2011/06/Proto.js Note how below, there is always an extra prototype in there with constructor functions. Super-calls (there will be syntactic sugar for this): - Constructor functions: Superclass.prototype.foo.call(this) - PAC: Superclass.foo.call(this) Subclassing: - Constructor functions: Subclass.prototype = Object.create(Superclass.prototype) - PAC: let Subclass = Object.create(Superclass) Instanceof (internally): - Constructor functions: o instanceof C === C.prototype.isPrototypeOf(o) - PAC: o instanceof C === C.isPrototypeOf(o) Problems that both prototypes-as-classes (PAC) and class literals (CL) are trying to solve are: - Subclassing is hard and not directly supported by the language: connecting prototypes, chaining constructors, super-references. Object.getPrototypeOf(this).foo.call(this) is pretty long. See above. It seems to me that perhaps the PaC drifted too far or perhaps started too far from what JavaScript has already. If the idea is to shift the focus more towards prototypes, then starting from something like what I've written and adding super syntax would be more consistent with what JavaScript already has. “too far from what JavaScript has already” is very vague. How so? With class literals, your code will look like PAC, anyway. Have you taken a look at Sect. 3? Do you agree that the mentioned conceptual simplifications hold? http://www.2ality.com/2011/06/prototypes-as-classes.html#3 I find Brendan’s anti-PAC argument much more convincing: that all people might find it more natural to think in terms of constructors than in terms of prototypes. If that is the case then PAC would be a bad idea. The other convincing anti-PAC argument is that it is a bad idea to have two class mechanisms. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) twitter.com/rauschma (http://twitter.com/rauschma) home: rauschma.de (http://rauschma.de) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es
Re: prototype focus
On Friday, 2011-07-01 at 16:38 , Mark S. Miller wrote: On Fri, Jul 1, 2011 at 7:18 AM, Sean Eagan seaneag...@gmail.com (mailto:seaneag...@gmail.com) wrote: On Fri, Jul 1, 2011 at 8:45 AM, Irakli Gozalishvili rfo...@gmail.com (mailto:rfo...@gmail.com) wrote: why do I have to create constructor function for all classes / subclasses ? This magic trades confusion for convenience. In any earlier version of the proposal, I actually had a traditional default constructor, the equivalent of constructor() { super(); } but others argued against it. Sorry don't remember who. There were plenty of off list discussions to gather consensus. On this one, I didn't feel strongly either way, but I eventually agreed with the objectors. When in doubt, throw it out -- even more important in language design than in writing. This could be handled by class literals by allowing for default constructors. If one doesn't provide a constructor, the following one could be provided: constructor(... args) { super(... args); } This one I object to because those used to other languages that provide such default constructors will only call the super constructor with no arguments. Though now that you mention it, I can see why JSers without exposure to other languages may naturally expect your's. With two expectations for the semantics of something that does not appear in the code, and without a static or dynamic rejection to prevent progress of the code written to the wrong assumption, I now finally feel strongly about this. The critics were right -- we should not provide any default constructor. Thanks for pointing out the problem case. Do you think prototype focused version: Prototype.new(foo); also suggest wrong assumptions ? If not (which I think is the case) is another + in favor of prototype focus. -- Cheers, --MarkM ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: prototype focus
On Friday, 2011-07-01 at 19:31 , Brendan Eich wrote: On Jul 1, 2011, at 6:19 AM, Irakli Gozalishvili wrote: With focus on prototype this is so much simpler: var Foo = Object.extend({ initialize: function(options) { ... }, do_foo_job: function() { ... } }) With | and 'super' in functions, I think you are set. It's hard to add more. The main debate is about whether this is enough, or do classes as sugar provide enough added value? (But you didn't show Bar as well as Foo.) Sorry I don't understand what did I failed to show in Bar ? My intent was to show that classes don't necessary need to have own constructors / initialization methods as they can be simply inherited via prototype chain. Or did you meant something else ? /be On Friday, 2011-07-01 at 11:10 , Axel Rauschmayer wrote: I don't think JavaScript has ever been far from its prototype roots especially if the programmer shifts to thinking about a prototype object instead of thinking about a functions prototype property. That is basically the point that the proposal tries to make. Have you taken a look at the library code? It is very short and not a radical overhaul. http://dl.2ality.com/dl/2011/06/Proto.js Note how below, there is always an extra prototype in there with constructor functions. Super-calls (there will be syntactic sugar for this): - Constructor functions: Superclass.prototype.foo.call(this) - PAC: Superclass.foo.call(this) Subclassing: - Constructor functions: Subclass.prototype = Object.create(Superclass.prototype) - PAC: let Subclass = Object.create(Superclass) Instanceof (internally): - Constructor functions: o instanceof C === C.prototype.isPrototypeOf(o) - PAC: o instanceof C === C.isPrototypeOf(o) Problems that both prototypes-as-classes (PAC) and class literals (CL) are trying to solve are: - Subclassing is hard and not directly supported by the language: connecting prototypes, chaining constructors, super-references. Object.getPrototypeOf(this).foo.call(this) is pretty long. See above. It seems to me that perhaps the PaC drifted too far or perhaps started too far from what JavaScript has already. If the idea is to shift the focus more towards prototypes, then starting from something like what I've written and adding super syntax would be more consistent with what JavaScript already has. “too far from what JavaScript has already” is very vague. How so? With class literals, your code will look like PAC, anyway. Have you taken a look at Sect. 3? Do you agree that the mentioned conceptual simplifications hold? http://www.2ality.com/2011/06/prototypes-as-classes.html#3 I find Brendan’s anti-PAC argument much more convincing: that all people might find it more natural to think in terms of constructors than in terms of prototypes. If that is the case then PAC would be a bad idea. The other convincing anti-PAC argument is that it is a bad idea to have two class mechanisms. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) twitter.com/rauschma (http://twitter.com/rauschma) home: rauschma.de (http://rauschma.de/) blog: 2ality.com (http://2ality.com/) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Summary: prototypes as classes
There have been multiple thread on this and I did not know were to comment, so I'll add few comments here. I think that whole constructors as classes business in JS is confusing for everyone coming to JS, and they only understand it after understanding confusing constructor- prototype relationship. It is true that people find var point = new Point(x, y) point instanceof Point intuitive but that's because it looks like Java. Also they are quite puzzled to find out that in some cases: var point = Point(x, y) works the same. On the other hand people may find Point.new(x, y) as intuitive, as they will think of ruby instead of java. Also, I do not think there is a point to use `constructor` with all it's confusing prototype relationships for initialization in prototypes as classes, just use initialize method to do that. Is it really too late to undo `constructor` as classes ? There are other proposals like rest and spread with a hope that `arguments` will die off some day. Why this would be different ? Finally I believe that killing constructors will make js straight forward to understand and lighter in syntax. And not everyone tries to emulate classical inheritance today: http://javascript.crockford.com/prototypal.html Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Thursday, 2011-06-30 at 24:24 , Axel Rauschmayer wrote: Last concrete disagreement we had was over new C() vs. C() in the current language being notably different from new C() vs. C.constructor() in the alternate-reality language with prototypes as classes. As in “don’t mix too well”. I agree with that. That will be a challenge for class literals. But the abstraction argument might apply to both cases: If people see a class C, they just want to instantiate it via new C(x,y). As long as instanceof works accordingly afterwards, I’m not sure much has changed *superficially*. -- Dr. Axel Rauschmayer a...@rauschma.de (mailto:a...@rauschma.de) twitter.com/rauschma (http://twitter.com/rauschma) home: rauschma.de (http://rauschma.de) blog: 2ality.com (http://2ality.com) ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Understanding Irakli’s code (new protocol)
On Friday, 2011-06-24 at 21:13 , Axel Rauschmayer wrote: I’m trying to understand all the implications of Irakli’s code. https://gist.github.com/d33befccbe1e0ed492d5 Object.prototype.new = function new() { return new this.constructor(); }; Object.prototype.extend = function extend(properties) { var constructor = new Function(), descriptor = {}; properties = properties || {}; Object.getOwnPropertyNames(properties).forEach(function(name) { descriptor[name] = Object.getOwnPropertyDescriptor(properties, name); }); descriptor.constructor = { value: constructor }; return Object.freeze(constructor.prototype = Object.create(this, descriptor)); }; Object.new = function new() { return Object.prototype.new(); }; Object.extend = function extend(properties) { return Object.prototype.extend(properties); }; Questions: 1. Do new and extend really work properly on any built-in other than Object? - E.g., I would expect String.extend() to lead to the invocation of Object.prototype.extend() which assumes this to be a prototype, but it is a constructor. - This could be fixed by checking whether this is a function and then acting accordingly. Or by setting up a constructor/class method extend for each built-in. I have not tried or thought much about other build-ins as showing idea was a main point. Yeah I was thinking that similar methods could be created per build-ins if necessary. 2. I don’t like that new() methods have to keep the result of super.new() and return it. I would prefer something like the code below, which enables a constructor behavior like in Allen’s example. I personally think that whole prototype, constructor and new keyword relationships add a lot of complexity to a language, and since this was fitting discussion nicely I though I'd share idea how this can be evolved to something more straight forward, that fits language much more IMO. I like new as a method because code is becomes simple and obvious. 3. Are my changes really an improvement or do they impede proper interaction with built-ins, somehow? = Library code = // Optional, possibly faster: split the method below into Object.prototype.new and Function.prototype.new (the latter overriding the former) Object.prototype.new = function new() { if (this instanceof Function) { return new this(); } else { return new this.constructor(); } }; // Performance is less of an issue for this method Object.prototype.extend = function extend(properties) { var superProto; if (this instanceof Function) { superProto = this.prototype; } else { superProto = this; } var descriptor = {}; properties = properties || {}; Object.getOwnPropertyNames(properties).forEach(function(name) { descriptor[name] = Object.getOwnPropertyDescriptor(properties, name); }); var thisProto = Object.create(superProto, descriptor); if (thisProto.constructor) { thisProto.constructor.prototype = thisProto; } thisProto.__super__ = superProto; return thisProto; }; // Optional: split the method below into Object.prototype.hasInstance and Function.prototype.hasInstance Object.prototype.hasInstance = function extend(instance) { if (this instanceof Function) { return instance instanceof this; } else { return this.isPrototypeOf(instance); } }; In my library I just use Foo.isPrototypeOf(bar); https://github.com/Gozala/selfish / Not necessary, any more (Object instanceof Object) Object.new = function new() { return Object.prototype.new(); }; Object.extend = function extend(properties) { return Object.prototype.extend(properties); }; / = Using the library = const SkinnedMesh = THREE.Mesh.extend({ constructor: function SkinnedMesh(geometry, materials) { SkinnedMesh.__super__.constructor.apply(this, arguments); // initialize instance properties this.identityMatrix = THREE.Matrix4.new(); this.bones = []; this.boneMatrices = []; }, update: function(camera) { ... // call base version of same method SkinnedMesh.__super__.update.call(this); } }); ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
Ok I wrote up another gist https://gist.github.com/7e649e8c33d412e90178 that no longer refers to any non-existing functions like `Function.create` and addresses `super` sugar issue using `base` function (In a similar way as in Dmitry's link). Also, implementation uses deprecated `caller`, non-standard `__proto__` , pseudo internal properties [[target]]', '[[name]]', '[[this]]' and function wrappers, but I hope / assume native implementation will be able to achieve same results without any of those. One disadvantage in comparison to `super` is that you can no longer call overlaid X methods from Y method, from my experience thats pretty rare case and can easily be workarounded. Alternatively base can have be improved using proxies to support base[X](a, b) case as well. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Monday, 2011-06-13 at 24:49 , Brendan Eich wrote: On Jun 12, 2011, at 3:38 PM, Irakli Gozalishvili wrote: On Monday, June 13, 2011, Brendan Eich bren...@mozilla.com (mailto:bren...@mozilla.com) wrote: On Jun 12, 2011, at 3:18 PM, Irakli Gozalishvili wrote:On Monday, 2011-06-13 at 24:03 , Brendan Eich wrote: On Jun 12, 2011, at 2:52 PM, Irakli Gozalishvili wrote: Here is gist I wrote before:https://gist.github.com/986487#file_implementation.js What Function.create are you using there? Is there a missing return statement in function extend? Yeap, sorry! It's there now. Ok. But what is that Function.create your gist relies on? It was proposed before I believe, it's like Object.create Function.create = function (proto, func) { var f = function() { return func.apply(this, arguments); } f.__proto__ = proto return f } No, that was too proxy-like. See http://wiki.ecmascript.org/doku.php?id=strawman:name_property_of_functions Starting at The major objection to losing Another idea I had was that super can be similar to private. Here is some example: Please note that the private(this)/private(other) syntax is intentional straw, to be burned up and replaced with something better. I think you're trying to self-host too much. People can write classes the hard way, with super too. They need sugar, not salt or pepper ;-). /be I just don't know how wild I can go with idea :) Isn't it better to leave off super for the moment and tackle that separately ? Not obviously. super outside of classes does not necessarily pay for itself (I did not remember it going to Harmony at the last meeting). And super inside of class should pay off as the classes proposal hopes -- 'super' in that context has no open issues. /be /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
Hi, Is there anything else (other than starting this thread) I can do to make committee consider `Function.prototype.extend` as an alternative to a proposed class sugar ? Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Tuesday, 2011-05-24 at 24:48 , Brendan Eich wrote: On May 23, 2011, at 11:25 AM, Bob Nystrom wrote: One thing I'd like the proposal to support, which it doesn't currently, is initializers on instance property declarations. Then you could do: class C { public _list = []; } With that, you'll correctly get a new _list on each instance of C when it's created. But (we've argued, I forget where so repeating it here), this looks like [] is evaluated once when the class declaration is evaluated. That is not what you intend. Then at some point (in the last thread on this) I remembered parameter default values, but they cover only missing parameters to the constructor. This _list member could be private. But it has to be initialized in a body that executes once per instantiation, which is not the class body -- it's the constructor body. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Sunday, 2011-06-12 at 23:18 , Brendan Eich wrote: On Jun 12, 2011, at 2:22 AM, Irakli Gozalishvili wrote: Hi, Is there anything else (other than starting this thread) I can do to make committee consider `Function.prototype.extend` as an alternative to a proposed class sugar ? Could you show Function.prototype.extend again, Here is gist I wrote before: https://gist.github.com/986487#file_implementation.js and say how it solves the super-construct and super-method-call problems? I don't have any (in js implementable solution) for those problems, also I think sugar for `super` can be a separate thing. Gist contains example with super that behave exactly the same as in harmony proposal for classes. /be Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Tuesday, 2011-05-24 at 24:48 , Brendan Eich wrote: On May 23, 2011, at 11:25 AM, Bob Nystrom wrote: One thing I'd like the proposal to support, which it doesn't currently, is initializers on instance property declarations. Then you could do: class C { public _list = []; } With that, you'll correctly get a new _list on each instance of C when it's created. But (we've argued, I forget where so repeating it here), this looks like [] is evaluated once when the class declaration is evaluated. That is not what you intend. Then at some point (in the last thread on this) I remembered parameter default values, but they cover only missing parameters to the constructor. This _list member could be private. But it has to be initialized in a body that executes once per instantiation, which is not the class body -- it's the constructor body. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, 2011-06-13 at 24:03 , Brendan Eich wrote: On Jun 12, 2011, at 2:52 PM, Irakli Gozalishvili wrote: Here is gist I wrote before: https://gist.github.com/986487#file_implementation.js What Function.create are you using there? Is there a missing return statement in function extend? Yeap, sorry! It's there now. and say how it solves the super-construct and super-method-call problems? I don't have any (in js implementable solution) for those problems, also I think sugar for `super` can be a separate thing. Gist contains example with super that behave exactly the same as in harmony proposal for classes. super.update(); // Desugars to: // Object.getPrototypeOf(Object.getPrototypeOf(this)).update.call(this); That comment is wrong, or worse: it implies the wrong spec. This function code does not want to depend on |this|, which could be rebound. You want to depend on the [[Prototype]] of the enclosing object, or if contained in class C syntax at the right level (not nested in arbitrary function expressions or inner function definitions), C.prototype.[[Prototype]]. Allen worked through this idea already: http://wiki.ecmascript.org/doku.php?id=harmony:object_initialiser_super Could be, I have not spend time thinking on super as I considered as separate issue. I'll take a look at Allen's work thanks for the link. Another idea I had was that super can be similar to private. Here is some example: function super(self) { var proto = Object.getPrototypeOf(Object.getProtypeOf(self)); Proxy.create({ ... get: function (receiver, name) { // Shorter to constructor would be nice: super(this).new(options) if (name === 'new') name = 'constructor' // make sure to apply for getter / setters / and methods only. // super(this).method(a, b) return proto[name].bind(self); } ... }, proto); } super(this).new(options); super(this).constructor(a, b); super(this).method(a, b); Obviously I don't suggest to use proxy, I just used to illustrate idea. Also please not that constructor will be enough as users will be able to implement getter `new` returning `this.constructor` on a base class for shorter syntax. /be /be Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France (http://goo.gl/maps/3CHu) On Tuesday, 2011-05-24 at 24:48 , Brendan Eich wrote: On May 23, 2011, at 11:25 AM, Bob Nystrom wrote: One thing I'd like the proposal to support, which it doesn't currently, is initializers on instance property declarations. Then you could do: class C { public _list = []; } With that, you'll correctly get a new _list on each instance of C when it's created. But (we've argued, I forget where so repeating it here), this looks like [] is evaluated once when the class declaration is evaluated. That is not what you intend. Then at some point (in the last thread on this) I remembered parameter default values, but they cover only missing parameters to the constructor. This _list member could be private. But it has to be initialized in a body that executes once per instantiation, which is not the class body -- it's the constructor body. /be ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org (mailto:es-discuss@mozilla.org) https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, June 13, 2011, Brendan Eich bren...@mozilla.com wrote: On Jun 12, 2011, at 3:18 PM, Irakli Gozalishvili wrote:On Monday, 2011-06-13 at 24:03 , Brendan Eich wrote: On Jun 12, 2011, at 2:52 PM, Irakli Gozalishvili wrote: Here is gist I wrote before:https://gist.github.com/986487#file_implementation.js What Function.create are you using there? Is there a missing return statement in function extend? Yeap, sorry! It's there now. Ok. But what is that Function.create your gist relies on? It was proposed before I believe, it's like Object.create Function.create = function (proto, func) { var f = function() { return func.apply(this, arguments); } f.__proto__ = proto return f } Another idea I had was that super can be similar to private. Here is some example: Please note that the private(this)/private(other) syntax is intentional straw, to be burned up and replaced with something better. I think you're trying to self-host too much. People can write classes the hard way, with super too. They need sugar, not salt or pepper ;-). /be I just don't know how wild I can go with idea :) Isn't it better to leave off super for the moment and tackle that separately ? -- Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Is class syntax really necessary ?
Hi, I think there lot's of proposals for ES.next that require syntax extensions, which is probably worth if new functionality added or shortens most commonly used constructs like functions (were no other option is available). In case of this proposal: http://wiki.ecmascript.org/doku.php?id=strawman:classes_with_trait_composition#open_issues even though I like it I'm not sure adding new syntax is worth it. I'm not suggesting that sugar for class composition is not necessary, example from three.js used by proposal highlights necessity pretty very well, I'm just thinking of doing that without introducing new syntax, here is one option: https://gist.github.com/986487 This way syntax noise may be reduced in addition this can be shimmed into current JS by implementing `Function.prototype.extend`. Also every single frameworks today does something similar in one form or another, IMO all is necessary is to have a standard that will let bikeshedding go away. I think there is also a good precedent of this with `Function.prototype.bind`. Here are some related links: http://documentcloud.github.com/backbone/ http://base2.googlecode.com/svn/version/1.0.2/doc/base2.html#/doc/!base2.Base http://prototypejs.org/learn/class-inheritance http://startdojo.com/2011/03/02/dojo-classes-inherited-and-constructors/ http://mootools.net/docs/core/Class/Class http://ejohn.org/blog/simple-javascript-inheritance/ Kind regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, 2011-05-23 at 13:10 , Dmitry A. Soshnikov wrote: On 23.05.2011 14:17, Irakli Gozalishvili wrote: Hi, I think there lot's of proposals for ES.next that require syntax extensions, which is probably worth if new functionality added or shortens most commonly used constructs like functions (were no other option is available). In case of this proposal: http://wiki.ecmascript.org/doku.php?id=strawman:classes_with_trait_composition#open_issues even though I like it I'm not sure adding new syntax is worth it. May I ask a counter question -- why do you think it's not good to add syntactic sugar for classes? It's a kind of a strange thing. People sometimes talk about unnecessarily of a sugar. But why I'm asking? Is it bad to use a sugar? Or do you _really_ worry about an _implementation_ that e.g. a language will be too heavy? After all, it's not even the issue of users, it's the issue of implementers. Dimitry thanks that's very good question. 1. More syntax means larger language surface, which adds complexity more things to remember / learn. More things to consider in ES.next.next 2. I OOP in JS is already confusing for people coming from other languages, this proposal will make it even more confusing. That is, since it's just a sugar, the users _still_ are free to use _desugared_ constructions (i.e. constructor + prototype + manual linkage of parent prototype in case of inheritance). If they want to. If they instead want to write with the sugar -- why we should worry about that adding of new syntax is worth (taking into account that `class`, `extends`, etc. keywords are already reserved since ES3 era). So from what I can tell, right after the sugar for classes is standardized, everyone will just start to use it and forget about desugared constructions. And nobody even will think and bother about whether it's worth or not. I don't doubt that, but adoption will take longer. A good point of standardizing this wrapper (which is just a sugar) is that all ad-hoc class-wrappers of libraries will be just eliminated and there will be common classes sugar from the box. Since JS already supports classical inheritance (though, without sugar), I don't how it's bad not to standardize the sugar for it. It will be convenient who need to program a class-based system. At the same time, if someone will still need a chaotic code reuse, i.e. a prototype-based inheritance (reuse a code from that object from which I want) -- they still be able to use things as `Object.create` (or | operator, etc.) From my perspective main problem today is verbosity, which can be fixed without introducing new syntax. Also while I named some disadvantages, I can't really see any advantages of dedicated syntax, there for I think it's better to avoid adding more syntax changes. I'm not suggesting that sugar for class composition is not necessary, example from three.js used by proposal highlights necessity pretty very well, I'm just thinking of doing that without introducing new syntax, here is one option: https://gist.github.com/986487 This way syntax noise may be reduced in addition this can be shimmed into current JS by implementing `Function.prototype.extend`. Yeah, OTOH, it can be so too. Though, the _familiar_ sugar will be bring the ability to involve programmers quicker. Also every single frameworks today does something similar in one form or another, IMO all is necessary is to have a standard that will let bikeshedding go away. Right. Dmitry. I think there is also a good precedent of this with `Function.prototype.bind`. Here are some related links: http://documentcloud.github.com/backbone/ http://base2.googlecode.com/svn/version/1.0.2/doc/base2.html#/doc/!base2.Base http://prototypejs.org/learn/class-inheritance http://startdojo.com/2011/03/02/dojo-classes-inherited-and-constructors/ http://mootools.net/docs/core/Class/Class http://ejohn.org/blog/simple-javascript-inheritance/ Kind regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, 2011-05-23 at 17:31 , Brendan Eich wrote: On May 23, 2011, at 6:11 AM, Irakli Gozalishvili wrote: On Monday, 2011-05-23 at 13:10 , Dmitry A. Soshnikov wrote: On 23.05.2011 14:17, Irakli Gozalishvili wrote: Hi, I think there lot's of proposals for ES.next that require syntax extensions, which is probably worth if new functionality added or shortens most commonly used constructs like functions (were no other option is available). In case of this proposal: http://wiki.ecmascript.org/doku.php?id=strawman:classes_with_trait_composition#open_issues even though I like it I'm not sure adding new syntax is worth it. May I ask a counter question -- why do you think it's not good to add syntactic sugar for classes? It's a kind of a strange thing. People sometimes talk about unnecessarily of a sugar. But why I'm asking? Is it bad to use a sugar? Or do you _really_ worry about an _implementation_ that e.g. a language will be too heavy? After all, it's not even the issue of users, it's the issue of implementers. Dimitry thanks that's very good question. 1. More syntax means larger language surface, which adds complexity more things to remember / learn. More things to consider in ES.next.next It's true, although not everyone learns it all up front. Especially where new syntax is not yet supported in all browsers, and the student is not using a compiler to translate new to old version. I think the sharper version of your (1) is: class syntax is too much syntax to solve the problems people have with prototypal inheritance: subclassed prototype/constructor set-up and super calls. I agree with that. Allen had been proposing super support that was separate. You proposed Function.prototype.extend. Perhaps there's enough there to relieve us of the large, tradition-haunted ediface of classes. 2. I OOP in JS is already confusing for people coming from other languages, this proposal will make it even more confusing. This is not as on target, in my opinion, because even if overwrought, classes are trying to solve some confusion or accident hazards in JS today to-do with prototypal inheritance. Namely, (A) the boilerplate needed to set up a sub-prototype object with correct constructor property, and (B) the pain of doing correct super calls by hand. Can we agree that these are problems to be solved, if not by classes then by other APIs or special forms? I do completely agree with that! /be ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, 2011-05-23 at 18:14 , Isaac Schlueter wrote: On Mon, May 23, 2011 at 08:51, Brendan Eich bren...@mozilla.com wrote: Class syntax is like a lint brush for such features. If we add it, it will accrete more semantics (with unambiguous syntax, I hope) over time. This is just inevitable, in my view. It makes me want to resist classes and look at smaller and more direct fixes for the two known prototypal hazards. Yes, please! I assume two known hazards is referring to your previous email: subclassed prototype/constructor set-up and super calls. I've been using this pattern in my OOP javascript programs lately: https://github.com/isaacs/inherits/blob/master/inherits.js It works really well, behaves as expected (easy for the author to say, ha, but it doesn't violate instanceof, doesn't call ctors more than once, doesn't clobber already-added prototype properties, etc.) And it's about 10 lines, easy to read and grok. I personally prefer backbone style as IMO it has advantage of keeping complete setup in one declaration statement. What would make it even nicer, however, with minimal added syntax: 1. Call super(a, b, c) instead of Child.super.call(this, a, b, c) 2. Maybe Parent.extend(Child) or Child.inherit(Parent) instead of inherits(Child, Parent) 3. Right now, calling parent versions of overridden methods is a painful: this.constructor.super.prototype.someMethod.call(this). It'd be nice to use something like super.someMethod(). ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Is class syntax really necessary ?
On Monday, 2011-05-23 at 18:47 , John Lenz wrote: The class syntax would be a great boon to the Closure Compiler. Much of ADVANCED mode optimizations depends on understanding class relationships, currently this means teaching it about each framework's extend or inherit methods and each of their subtleties. If there will be build-in `Function.prototype.extend` it will be pretty easy to teach closure compiler to take advantage of that. On Mon, May 23, 2011 at 4:10 AM, Dmitry A. Soshnikov dmitry.soshni...@gmail.com wrote: On 23.05.2011 14:17, Irakli Gozalishvili wrote: Hi, I think there lot's of proposals for ES.next that require syntax extensions, which is probably worth if new functionality added or shortens most commonly used constructs like functions (were no other option is available). In case of this proposal: http://wiki.ecmascript.org/doku.php?id=strawman:classes_with_trait_composition#open_issues even though I like it I'm not sure adding new syntax is worth it. May I ask a counter question -- why do you think it's not good to add syntactic sugar for classes? It's a kind of a strange thing. People sometimes talk about unnecessarily of a sugar. But why I'm asking? Is it bad to use a sugar? Or do you _really_ worry about an _implementation_ that e.g. a language will be too heavy? After all, it's not even the issue of users, it's the issue of implementers. That is, since it's just a sugar, the users _still_ are free to use _desugared_ constructions (i.e. constructor + prototype + manual linkage of parent prototype in case of inheritance). If they want to. If they instead want to write with the sugar -- why we should worry about that adding of new syntax is worth (taking into account that `class`, `extends`, etc. keywords are already reserved since ES3 era). So from what I can tell, right after the sugar for classes is standardized, everyone will just start to use it and forget about desugared constructions. And nobody even will think and bother about whether it's worth or not. A good point of standardizing this wrapper (which is just a sugar) is that all ad-hoc class-wrappers of libraries will be just eliminated and there will be common classes sugar from the box. Since JS already supports classical inheritance (though, without sugar), I don't how it's bad not to standardize the sugar for it. It will be convenient who need to program a class-based system. At the same time, if someone will still need a chaotic code reuse, i.e. a prototype-based inheritance (reuse a code from that object from which I want) -- they still be able to use things as `Object.create` (or | operator, etc.) I'm not suggesting that sugar for class composition is not necessary, example from three.js used by proposal highlights necessity pretty very well, I'm just thinking of doing that without introducing new syntax, here is one option: https://gist.github.com/986487 This way syntax noise may be reduced in addition this can be shimmed into current JS by implementing `Function.prototype.extend`. Yeah, OTOH, it can be so too. Though, the _familiar_ sugar will be bring the ability to involve programmers quicker. Also every single frameworks today does something similar in one form or another, IMO all is necessary is to have a standard that will let bikeshedding go away. Right. Dmitry. I think there is also a good precedent of this with `Function.prototype.bind`. Here are some related links: http://documentcloud.github.com/backbone/ http://base2.googlecode.com/svn/version/1.0.2/doc/base2.html#/doc/!base2.Base http://prototypejs.org/learn/class-inheritance http://startdojo.com/2011/03/02/dojo-classes-inherited-and-constructors/ http://mootools.net/docs/core/Class/Class http://ejohn.org/blog/simple-javascript-inheritance/ Kind regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: arrow syntax unnecessary and the idea that function is too long
On Sunday, 2011-05-08 at 20:48 , Peter Michaux wrote: On Sun, May 8, 2011 at 11:34 AM, Irakli Gozalishvili rfo...@gmail.com wrote: I'd like to point out that coffeescript has a huge success and in the end it's just syntax sugared js. Can someone give evidence that Coffeescript is actually a success? Has anyone crawled the web to determine the rate of Coffeescript adoption? (Assuming there is some way to identify Coffeescript's compiled code.) Will adoption plateau at a small percentage of total browser scripts? Coffeescript is one of the most watched projects on github. Which I'd say is pretty big for such a young project. https://github.com/popular/watched People cannot just reiterate this idea that Coffeescript is popular and use that as support for arrows without evidence that Coffeescript is actually popular. Let's ignore popularity level for the moment, no other proposal has analog of `=` which is a solution for a real problem: var self = this; function callback() { self } Peter ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: On what we consider to be beautiful lambda expressions...
On Monday, 2011-05-09 at 10:02 , François REMY wrote: We’ve seen many proposals and arguments in the current thread about the arrow syntax. While it’s great to start with a brainstorm, the discussion should be, at some time, recentered on how to write beautiful lambda expressions. The objective of the “short” function syntax [if it once gets implemented] would be to have a nicer way to write lambdas (keeping that in mind during the discussion is important because, for the other uses, the classical “function” syntax will still be applicable). I think shorter function syntax is a goal which is not limited to lambdas only. We all know we have our own prefered syntax based on our tastes and our experience with other languages. While the fact that the ECMAScript comitee can’t choose something that will make everybody happy, it should at least try to evaluate the pro and cons of all possibilities (rejecting a proposal because it use a symbol that may be used in the Private Name proposal seems to me a little weird, since we also could use another symbol or name in the Private Name proposal and/or in the new function notation proposal). Evaluating the best proposal should be done by : - identifying use cases of lambdas - seeing what’s the current patterns used at this time to solve those uses cases - in ES today (and in libraries like jQuery, Prototype.js, ...) - in other programming languages (seems to have been done in large part by the precedent mails) - seeing how to improve those use cases (and if it’s needed) - considering what’s the best solution from three point of view : - Compiler (ease of parsing) - IDE (ease of implementation) - Developer (readability / writability) Maybe some people in the comitee are already performing that work, so I’ll not attempt to go more in depht into this. To make some progress on the subject, here’s a little summary of the available proposals, at this time : // CSharp-like syntax array.filter((x) – x.isEmpty); // MatLAB-like syntax array.filter(@(x) x.isEmpty); array.filter(#(x) x.isEmpty); // VB-like syntax array.filter(function(x) x.isEmpty); array.filter(function(x) { return x.isEmtpy; }) Other proposals were the following (but I suspect the syntax is problematic) : // Ruby-like syntax (?) array.filter({|x| x.isEmpty}); array.filter((x){x.isEmpty); I don’t know if it’s derisable, but we could do even shorter (and readable) by making the assumption that *if* no argument list is provided, then the lamda takes only one named argument (that could be called “a”, considering that no good developer would use this single letter as variable names outside lambdas). This would allow the following additionnals : array.filter(-a.isEmpty); array.filter(@a.isEmpty); array.filter(#a.isEmpty); array.filter(function a.isEmpty); As I already previously said, I kinda like the @-proposal [[ array.filter(@a.isEmpty); ]] because it’s very short to write, it’s easy to understand, very similar to the current syntax (an important point that the arrow syntax completely miss) and can be acustomated to more complex cases like [[ array.filter(@(childArray,childIndex) { for(var i=0; ichildArray.length; i++) { if(i%2==0 a[i]=0) return false; } return true; }); ]] Something to be pointed out is that in the case of more complex functions, the most readable way is often to create a “true” fuction and use its name as the filter argument [[ var isValid = @(childArray,childIndex) { for(var i=0; ichildArray.length; i++) { if(i%2==0 a[i]=0) return false; } return true; }; array.filter(isValid); ]] Another fact used in the discussion is that the arrow proposal provides a way to ‘bind’ a lambda to an element. Sorry, I’m not sure about why this is useful to have two kind of lambdas. A lambda is, most of the time, a function that’s independant of the place where’s it is written, used to perform a simple test. The most common use of ‘bind’ is to send an object’ function as a callback to an asynchronous code (event, ). In this case, you’ll not create a lambda because the original function already exists [[ el.onclick=this.removeFromParent.bind(this) vs el.onclick=()=this.removeFromParent() ]]. I think your assumption that short function syntax is only for lambdas is false. Also here is some real world examples of self = this pattern that is solved by = http://www.google.com/codesearch?hl=enlr=q=self\s*%3D\s*this%3B\s*function+lang%3Ajavascript+case%3Ayessbtn=Search http://www.google.com/codesearch?hl=enlr=q=.bind\%28this+lang%3Ajavascript+case%3Ayessbtn=Search It’s however possible to say that @-function (aka lambdas) are automatically bound to the current “this”, if needed. It would allow things like [[ array.filter(@this.isValidChild(a)); ]] to work
Re: arrow syntax unnecessary and the idea that function is too long
On Monday, 2011-05-09 at 11:02 , Kyle Simpson wrote: Let's ignore popularity level for the moment, no other proposal has analog of `=` which is a solution for a real problem: var self = this; function callback() { self } Maybe I missed something, but didn't Brendan's #-function proposal specify lexical `this` binding, so that: function foo() { this.bar = baz; return #(x){ this.bar = x; }; } Isn't that the spirit of what = would give us? Yes and this case makes following example extremely confusing: MyObject.prototype.bar = #(x) { this.bar = x } Is this instance of MyObject ? So we need to use `#` in some places, but in other cases we need to stick to long form `function`. I think `-` and `=` is way more intuitive and simple. --Kyle ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: arrow syntax unnecessary and the idea that function is too long
I'm really happy that arrow syntax proposal was made and thanks a lot Brendan!! I'd like to point out that coffeescript has a huge success and in the end it's just syntax sugared js. I think this is quite good proof that syntax change like this is more then welcome. Another thing I'd like to point out that arrow function is not just saving keystrokes of typing `function` and `return`, but also gives even bigger win IMO via `=` when binding of `this` pseudo variable is desired. This case BTW was not addressed by `#`. Even though `-` is one more char in comparison to `#`, `=` is much less then `.bind(this)`, in addition having both - and = feels just natural! Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France On Sunday, 2011-05-08 at 19:09 , Rick Waldron wrote: Just read https://mail.mozilla.org/pipermail/es-discuss/2008-November/008218.html and I'm buzzing with the idea of Lisp style functions as inspiration for a short hand. While I realize the idea is likely absurd, but I'm thinking in terms of concepts that _all_ JavaScript devs know and understand. This is a super simple, first-pass, rough-draft, not-too-serious, request-for-comments... https://gist.github.com/961495 Rick On Sun, May 8, 2011 at 1:51 PM, Faisal Vali fais...@gmail.com wrote: On Sun, May 8, 2011 at 4:04 AM, Jorge jo...@jorgechamorro.com wrote: On 08/05/2011, at 05:52, Faisal Vali wrote: (...) I find the aesthetics of the arrow-syntax far more consistent with javascript's C-based-syntactic roots than the preprocessor-tainted '#' (...) Consistent ? - in C has a *totally* different meaning ! Yes, but that is why I alluded to a syntactic commonality and not a semantic one. But, I can see how the disparity in semantics might bother some programmers. ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
harmony:modules with require
Hi, I just noticed that harmony modules have a different spelling then it used to have: module YUI = 'http://developer.yahoo.com/modules/yui3.js'; module YUI = require('http://developer.yahoo.com/modules/yui3.js'); I wanted to know what was a reason for such a change. I am also concerned that this will bring quite a confusion as `require` is pretty well adopted function this days while spelling of it's modules is pretty much different. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Standardizing more de facto functions
Hi, I just recently found out that `Object.prototype.trimLeft / trimRight` are not part of ES5. Still many modern browsers (FF, Safari, Chrome) implement it. Would you consider standardizing them for harmony ? Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: About private names
On Mon, Mar 21, 2011 at 19:29, Andrew Dupont mozi...@andrewdupont.netwrote: On Mar 21, 2011, at 11:14 AM, Brendan Eich wrote: Hi Andrew, thanks for the good thinking on this thread. I'm not cherry-picking here, but I wanted to reply to the specific sentence ending entire lexical scope. The Harmony top-level scope (no global object!) will be big and it may even grow by (non-colliding) extension, sure. Hence Dave's thought of not allowing private there. Anyway, I wanted to check this (what I took to be your own experience-based) weighting of search space sizes. This is a good point — I'm imagining lexical scopes that, at their largest, can span the entirety of a very large library like Prototype or jQuery. In recent years, Prototype has moved toward defining each of its sections in a separate anonymous function, declaring named functions inside of it, then selectively exporting some of them to the global scope. This is an increasingly common trend. In the future, I can see us moving toward a system where the whole library follows that pattern — one giant anonymous function surrounding the whole thing. Not allowing private in the top-level scope would help a bit (at the cost of hindering the Conflict-Free Object Extension Using Private Names use case), but any lexical scope can grow to a staggering size. On Mar 21, 2011, at 11:14 AM, Brendan Eich wrote: Is a lexical scope bigger and harder to search than two or more class files in Java? Ignoring IDEs, this seems to suggest lexical scopes tend to be big. Is this based on your experience with JS blocks (not function bodies or global scopes) today? Until now, yes, I have been imagining a function body as an example of a lexical scope. Why are you excluding it? On Mar 21, 2011, at 3:11 AM, Irakli Gozalishvili wrote: Also I think this proposal won't be really useful without syntax sugar. To elaborate more, I think this is a perfect feature for libraries that extend built-ins like prototype, or mootools or their extensions may be defined as private names that consumers may decide to use by importing names, or rename or just ignore entirely. I'm co-maintainer of Prototype and I'm saying I can't imagine we'd use this feature under the proposed syntax. And — again — I'm not opposed to syntactic sugar in general, only to this specific syntax. Andrew I think you misunderstand this feature, as prototypejs is a perfect fit for it!! What I mean is that prototype could define all the extensions names it introduces in the top of the lexical scope and export those names along with framework. That will allow consumers to choose which extensions they intend to import and which not. Some even may decide to change names (bike-shedding is very popular in JS :) Here is an example: -- lib.js -- private clone; private extend; Object.extend = function() {} Object.prototype.clone = function() { } Array.prototype.clone = function() { ... } exports.extend = extend; exports.clone = clone; -- consumer.js -- private clone = require(lib.js).clone; private superExtend = require(lib.js).extend { a: 'b' }.clone(); // { a: 'b' }; Object.extend = function () { Object.superExtend.apply(...); // do something else } // note that extend does not overrides `extend` defined by lib.js My point is that library can uses internal names as they used it before, but if they will define their extensions as names they make them opt-in for consumers of lib. On Mar 21, 2011, at 11:50 AM, David Herman wrote: This is true. But because *you* control the local view of the private name, and that local binding is not exposed to anyone else, you can always rename your local name out of the way. People keep saying this. It may be true, but it undermines one of the stated goals of the proposal. The whole point of Prototype's built-in extension is to introduce more intuitive ways of working with built-ins and to fill perceived gaps. Naming is a large part of that. `{}.myClone` is, in my view, vastly inferior to `{}.clone` because of its unintuitive naming. As a hypothetical consumer, I'm hardly impressed with a library that promises conflict-free usage of an instance method on objects... as long as I name the method uniquely and am careful about scoping. On Mar 21, 2011, at 11:50 AM, David Herman wrote: How often would people really bind private names in large scopes? I honestly -- in good faith -- don't know. Well, again, the Conflict-Free Object Extension Using Private Names use case explicitly encourages using private names in large scopes. But I don't know either; I'm just trying to give my perspective as a library author. _Everything_ about this syntax screams footgun, both for me and for users of Prototype. Aside from writing large amounts of code with the proposed syntax, I'm not sure what I can do to illustrate this, but I'm open to ideas. Cheers, Andrew
Question regarding ES5
Hi, I've run into one issue and even after reading ES5 specs several times it's not clear to me what should be an expected behavior: Currently on Firefox nightly following code: (function() { use strict; function Type() {} Object.freeze(Type.prototype); var object = Object.create(Type.prototype); object.constructor = function Foo() {}; return object })(); throws TypeError: object.constructor is read-only while on chrome it returns object with constructor Foo I would like to know what is an expected behavior to fill a bug to an appropriate project. Thanks! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Question regarding ES5
Thanks for the reply Allen, I was under the impression that inherited properties can be overridden, regardless of their write-ability on the __proto__. Also as far as I understand freeze will make properties including constructor non-confugurable, will I still be able to override such properties using Object.defineProperty ? Also this was simplified example and it's not really possible to do the freeze after. Will try `Object.defineProprety` though. Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Thu, Feb 17, 2011 at 02:21, Allen Wirfs-Brock al...@wirfs-brock.comwrote: The error looks correct to me. By freezing Type.proto you make all its own properties read only. One of those is the constructor that is automatically created on every func.prototype object. When you assign to object.constructor you are trying to over-ride an inherited read-onoy property. ECMAScript has never allowed this. You can say: Object.defineProperty(object,constructor,{value: function Foo() {}, /* any other attributes you want to set */}); to over-ride the inherited constructor property. Or you can restructure you code so you do the freeze after you do the assignment. On Feb 16, 2011, at 5:09 PM, Irakli Gozalishvili wrote: Hi, I've run into one issue and even after reading ES5 specs several times it's not clear to me what should be an expected behavior: Currently on Firefox nightly following code: (function() { use strict; function Type() {} Object.freeze(Type.prototype); var object = Object.create(Type.prototype); object.constructor = function Foo() {}; return object })(); throws TypeError: object.constructor is read-only while on chrome it returns object with constructor Foo I would like to know what is an expected behavior to fill a bug to an appropriate project. Thanks! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, Francehttp://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Question regarding ES5
I have not found a way to cc people but here is the link for a bug report: http://code.google.com/p/v8/issues/detail?id=1169 I think if you'll star it you'll get an updates over email. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Thu, Feb 17, 2011 at 02:34, Brendan Eich bren...@mozilla.com wrote: Please do file that bug (issue) against V8, though :-P. You can cc: me as bren...@mozilla.org on it. /be On Feb 16, 2011, at 5:32 PM, Irakli Gozalishvili wrote: Thanks for the reply Allen, I was under the impression that inherited properties can be overridden, regardless of their write-ability on the __proto__. Also as far as I understand freeze will make properties including constructor non-confugurable, will I still be able to override such properties using Object.defineProperty ? Also this was simplified example and it's not really possible to do the freeze after. Will try `Object.defineProprety` though. Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, Francehttp://goo.gl/maps/3CHu On Thu, Feb 17, 2011 at 02:21, Allen Wirfs-Brock al...@wirfs-brock.comwrote: The error looks correct to me. By freezing Type.proto you make all its own properties read only. One of those is the constructor that is automatically created on every func.prototype object. When you assign to object.constructor you are trying to over-ride an inherited read-onoy property. ECMAScript has never allowed this. You can say: Object.defineProperty(object,constructor,{value: function Foo() {}, /* any other attributes you want to set */}); to over-ride the inherited constructor property. Or you can restructure you code so you do the freeze after you do the assignment. On Feb 16, 2011, at 5:09 PM, Irakli Gozalishvili wrote: Hi, I've run into one issue and even after reading ES5 specs several times it's not clear to me what should be an expected behavior: Currently on Firefox nightly following code: (function() { use strict; function Type() {} Object.freeze(Type.prototype); var object = Object.create(Type.prototype); object.constructor = function Foo() {}; return object })(); throws TypeError: object.constructor is read-only while on chrome it returns object with constructor Foo I would like to know what is an expected behavior to fill a bug to an appropriate project. Thanks! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, Francehttp://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: promises | Communicating Event-Loop Concurrency and Distribution
On Fri, Jan 28, 2011 at 01:09, Mark S. Miller erig...@google.com wrote: On Thu, Jan 27, 2011 at 8:00 AM, Irakli Gozalishvili rfo...@gmail.comwrote: Hi, I was curious to know what is the state of the following proposal: http://wiki.ecmascript.org/doku.php?id=strawman:concurrency It's on the agenda for the upcoming March meeting. I was planning to do some more work on it before declaring it ready for discussion. But since you raise it, I'm happy enough with it in its current state. I can clarify my remaining issues with it as discussion proceeds. So This page is now ready for discussion. I do expect that this strawman is too large to be accepted into ES-next as a whole. To get some of it accepted -- syntactic sugar + some supporting semantics -- we need to find a clean boundary between what kernel and extension mechanism the platform needs to provide vs the remaining functionality that should be provided by libraries using these extension mechanisms. For example, Tyler's web_send uses such an extension API in ref_send to stretch these operations onto the network, by mapping them onto JSON/RESTful HTTPS operations. Kris Kowal's qcomm library uses Q.makePromise (like that proposed above) to stretch these operations over WebSockets, whose connection-oriented semantics enables a better mapping at the price of more specialized usage. I hope that Kevin Reid's caja-captp can also be reformulated as a library extending the Q API. (See links to ref_send, web_send, qcomm, and caja-captp at the bottom of the strawman page.) I'm familiar with those libraries and actually I have a fork of Kris's q-comm where I prototyped de-sugared implementation of this proposal for Mozilla Jetpack, where it will allow cross process async messaging. https://github.com/Gozala/vats I do believe that having ES native promises could provide drastically better alternative for writing async code in comparison to currently popular nested callback style. Also even though there are few implementations of Q API adoption is still low IMO that's due to non obvious and verbose syntax. Syntactic sugar described in the proposal really makes a lot of difference. Also I don't see proposal for `Q.when` syntax and would love to know what is the a plan for that. Given a lightweight closure syntax, I don't think Q.when actually needs any further syntactic sugar. For example, here's the asyncAnd example from Figure 18.1 of http://erights.org/talks/thesis/ in JS with this strawman + destructuring + the lightweight closure syntax from HOBD (Harmony of Brendan's Dreams): #asyncAnd(answerPs) { let countDown = answerPs.length; if (countDown === 0) { return true; } const {promise, resolver} = Q.defer(); answerPs.forEach(#(answerP) { Q.when(answerP, #(answer) { if (answer) { if (--countDown === 0) { resolver(true); } } else { resolver(false); } }, #(ex) { resolver(Q.reject(ex)); }); }); return promise; } The original asyncAnd in Figure 18.1 is in E, whose syntax was designed without legacy burden to make such code pleasant. Nevertheless, I don't think the code above suffers much in comparison. Of course, if you have a suggestion of how a sugared Q.when can improve on this enough to be worth the cost of yet more sugar, please suggest it. Thanks. I see your point, I was actually thinking of an E like syntax, but I do agree that Q.when is good enough, but then there still should be some build-in APIs to allowing to build Q.when on top, which leads me to a few questions: 1. Is there supposed to be a build-in type that will represent a promise ? 2. I believe there should be a build-in API to test whether value is promise or not, how that will look ? 3. There should be build-in API to create / fulfill / brake promises and also observe state changes, which will allow lib implementers to implement Q.when like methods. Also I think it would be useful to split up proposal into 2 parts: 1. Concentrating on promises and eventual operations 2. vats Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, Francehttp://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss -- Cheers, --MarkM ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
promises | Communicating Event-Loop Concurrency and Distribution
Hi, I was curious to know what is the state of the following proposal: http://wiki.ecmascript.org/doku.php?id=strawman:concurrency I do believe that having ES native promises could provide drastically better alternative for writing async code in comparison to currently popular nested callback style. Also even though there are few implementations of Q API adoption is still low IMO that's due to non obvious and verbose syntax. Syntactic sugar described in the proposal really makes a lot of difference. Also I don't see proposal for `Q.when` syntax and would love to know what is the a plan for that. Thanks -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Extending natives in simple modules
Hi, I have noticed that [simple modules]( http://wiki.ecmascript.org/doku.php?id=strawman:simple_modules) don't mention how does natives are supposed to behave across modules. Are they shared or each module gets it's own Object, Function, Array, ... objects ? I think this is something that should be discussed / specified. Also some popular libraries (prototype, sproutcore, extjs, fusejs) depend on extended natives. FuseJS for example even uses iframe based sandboxing approach for extending natives to avoid conflicts. IMO it would've be very nice if module had a different natives so that they could extend those without any compatibility risks with other libs. Also in that case would be nice to have convenient syntax for deciding whether or not extension on natives are imported along with module. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: Classes as Sugar is now ready for discussion
Hi, Not a long time ago we also started using traits at [Jetpack]( http://mozillalabs.com/jetpack/) and so far it seems to work pretty well for us. In contrast to bespin though we don't use traitsjs.org instead we have our own implementation which pretty much follows same APIs (one major difference is non-|this|-bounded objects are created). BTW there is another framework that was using traits for a long time http://joose.it/ not sure how widely adopted framework is though. Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Sat, Sep 11, 2010 at 01:55, David Herman dher...@mozilla.com wrote: Yes, that's an accurate summary. It also brings me back to Dave's earlier question about the limited choices provided by the Traits library. ... Long story short: it's definitely possible for a Traits library to offer more knobs, although I'm not sure whether the increased complexity is worth it. Just to be clear, I wasn't saying we should consider *more* knobs, just that other knobs are possible. I'm not convinced that the Trait.create knob offered by traits.js is necessary. Judging from earlier comments, it seems there is at least a niche for the combination of 'early conflict detection' + 'non-frozen, non-|this|-bound objects'. I'm told this is what our colleagues working on Skywriter would have preferred. Dave ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: death to style guidelines
I do understand that just switching a skin is no go, but having something like: use clean; Could be a very good compromise. Regarding my phrase on coffee: I did not meant to heart anybody's feelings regarding coffee script. I do like the project myself but I don't think it production ready. Here is the quote from the coffee script website: *Disclaimer:* CoffeeScript is just for fun. Until it reaches 1.0, *there are no guarantees that the syntax won't change between versions.* * *Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Thu, Sep 2, 2010 at 10:52, Dmitry A. Soshnikov dmitry.soshni...@gmail.com wrote: On 02.09.2010 2:44, Mike Samuel wrote: 2010/9/1 Irakli Gozalishvili rfo...@gmail.com rfo...@gmail.com: I have not seen the post before, but it perfectly expresses my concerns. I still do think though that if breaking backwards compatibility is on the table solving syntactic noise issue is not such a bad idea even if it means changing a skin it makes devs more aware of a change. Both skulpt coffee are good toys, but don't think it's practical to use them for a real apps. Actually, CoffeeScript is off-topic here. When I was mentioned it, I didn't mean let's make a Coffee from JS, I just noticed how elegantly Coffee improves some syntactic constructs over JS. However, I'd like to mention that -- you're kidding me, right (about the toy without practical usage)? Coffee is a new language. And the only relationship with JavaScript, is that it's inspired by JavaScript (but actually by Ruby) and improves some constructions (syntactically and, as a consequence, increasing and abstraction). It's good to write a new highly-abstracted language, using another highly-abstracted language (in this case JavaScript). If will be needed (if will be talks about performance), it may be rewritten using less-abstracted languages (e.g. C, Assembler) and then it will be a completely separated from JavaScript language which is (the same as JavaScript, Python, Ruby, etc.) just another good general purpose scripting language -- with its own pros and cons. Moreover, CoffeeScript syntactically mostly inspired by Ruby (in it's nature, Coffee isn't even prototype-based, it encapsulates this stuff into the sugar of classes; JavaScript is used only to implement Coffee. And as you know, the latest version of Coffee is already written on Coffee itself but not on JavaScript). If it will have a strong support (by committees, browsers, etc), it may win JavaScript. But I don't think it will in nearest future (the same useless talks about Python and Ruby native support in nowadays for browsers). However, if not to translate/compile Coffee's code into JS-code at runtime, but with static preprocessing -- having as an output ready JS-code-generated files, and then just include these js-files to the project -- it normally may be used in projects today. There is a lack with debugging in this case, but I think it may be solved somehow. And regarding JS, yeah, backward compats matter and it's really not-practical to switch the skin so radically. However, since ES has use strict feature which is, besides being a helper for inattentive programmer, also is used as a deprecated/obsolete stuff notifier (e.g. with-statement), it may be used in future for the same role -- removing old-style/deprecated syntactic garbage, and replacing it with alternative constructs. (Because e.g. when C was creating its switch-cases with known today non-logical behavior, its decision was related with *problems and issues* of code-generation (e.g. in Assembler) -- it was needed that break, because it's just a jmp from the block. But when other languages (Java, JavaScript) just repeat this syntax construct completely after C, they just thought about to be a new language with already-known syntax. And attempts to improve some constructs of previous language, would break this aim). P.S.: I'm really sorry for such a big off-topic. BTW blessing one of the coding styles as Dmitry suggested may be a successful attempt for solving at least half of the issue. Might blessing a style guide be better done by a software producing organization like Mozilla or JQuery than by a standard producing organization like TC39? Yeah, right... But, since there is a (formal?) language named ECMAScript, maybe it worth to write at least some *recommendation* for a coding style. At least with naming convention of properties/methods. The spec itself prompts a programmer that methods should be named in camelCase, that constructors should be named in upper CamelCase, etc. If an official site of the technology will have such a recommendation (I repeat, even Python with it's hard-coded syntax rules has additionally PEP8 -- to (recommend to) name properties/methods in uderscore_case), then we'll see that many companies when
death to style guidelines
Hi, Please don't be too aggressive in replies, I know it's too ambitious may not lead to anything, but I still want to give it a try and suggest to: Employ some of the decisions that being made with coffee script python in order to over all the wars regarding: 2 space vs 4 space vs tabs, where to put braces, whether or not use optional semicolons. All the style guidelines, just hurt developers, who have to switch mentally every time they work on a project with a different style guides. Besides if I follow correctly it's being agreed to make backwards incompatible syntax changes in new version of ECMAScript :) As a side note, I'd like to also mention that coffee script managed to reduce verbosity so match, making writing code so much better experience! Regards! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: ASI and wrapping long lines
Another pattern of solving this that people writing semicolonless code already employ is: function a() { return ( some string ) } Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Phone: +31 614 205275 Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu On Tue, Jul 27, 2010 at 00:29, Allen Wirfs-Brock allen.wirfs-br...@microsoft.com wrote: I confess that I haven’t waded through the entire Rationalizing ASI thread. I generally agree with Brendan concerning the horse and the barn. However, there was one ASI problem that was raised for which I think we could at least provide a basic remediation: We talked at the July 2008 Oslo (Harmony) meeting about one way to mitigate the unreported dead-code error that results from function foo() { if (some) { if (deep) { if (random) { if (logic) { if (ending) { if (in_a_very_long) { return I believe in the 80 column limit, so I wrapped; } } } } } } return LOL; } The problem here is that the programmer has a legitimate reason to want to break a return across two lines and they can’t. There is an easy fix for this. It’s called “line continuation”. In ES5 we standardized the de facto browser behavior for line continuation within string literals: LineContinuation :: \ LineTerminator Sequence. A LineContinuation certainly could also be allowed as an alternative for whitespace. Then if [no LineTerminator here] is reinterpreted to not match a LineContinuation then the above return could have been written as: return \ I believe in the 80 column limit, so I used a LineContinuation; It wouldn’t help people who didn’t know about line continuation but it would allow those who do know about them the flexibility to format their code the way they want it. I would normally say a language shouldn’t need cruft like this. However, once you’ve go down the road of making line breaks syntactically significant it is arguably reasonable to also allow for line breaks that explicitly have no syntactic significance. Allen ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
Re: simple shorter function syntax
On Mon, Jul 26, 2010 at 10:15, Dmitry A. Soshnikov dmitry.soshni...@gmail.com wrote: That's look interesting, yeah, I (personally) like it. Also beside = can be used traditional function definition sign of some functional (and not only functional) languages: - Coffee (while using - for functions) uses = sugar for binding the `this` value with defining a function at the same time: http://jashkenas.github.com/coffee-script/#fat_arrow which I think also a good sugar for `.bind` method. + 1 (my two cents here) Another I thing good point here is that CoffeeScript is a working successful proof of concept and many webdevs are already familiar with it. Acquiring even more of it's syntax may be a good ide!! Regards -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Phone: +31 614 205275 Address: 29 Rue Saint-Georges, 75009 Paris, France http://goo.gl/maps/3CHu ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss
getter / setters
Hi, Sorry if my question is stupid or does not really belongs here. I will be thankful to get some clarification on es specs since I just discovered that my interpretation of how getter / setters are supposed to behave appears to be different from the behavior in observed in modern browsers. var foo = Object.create({}, { bar: { get: function() { return this._foo; }, set: function(value) { return this._foo = 'Hello ' + value; } } }); var bar = foo.bar = 'setter'; if (foo.bar !== bar) throw new Error('Unexpected'); The code will throw an error cause bar will be 'setter' while foo.bar will be 'Hello setter'. I was expecting that `bar' would've get value returned by a setter (or at least getter of foo). And this is not the case nor with FF nor with Safari implementations. Behavior is the same if getters and setters are used instead. Is it expected behavior ? If answer is yes, is there any point of returning anything from setter ? I am also afraid that this might break some of the frameworks in rare cases like in this example above. (a = b = c is commonly used syntax) Thanks a lot! -- Irakli Gozalishvili Web: http://www.jeditoolkit.com/ Phone: +31 614 205275 Address: Taksteeg 3 - 4, 1012PB Amsterdam, Netherlands ___ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss