Re: Using Object Literals as Classes

2012-03-24 Thread Claus Reinke
(function () {}) creates two object, not one. I'm not sure what you meant here. .. the empty object for the function's .prototype currently seems to elude me in all its forms.. Claus ___ es-discuss mailing list es-discuss@mozilla.org

Re: Using Object Literals as Classes

2012-03-18 Thread Herby Vojčík
Allen Wirfs-Brock wrote: On Mar 17, 2012, at 1:20 PM, Herby Vojčík wrote: Allen Wirfs-Brock wrote: This has nothing to do with classes. It is just basic prototypal inheritance and the semantics of the new operator and function expressions. Well, seems convincing... but nevertheless, I see it

Re: Using Object Literals as Classes

2012-03-17 Thread Kevin Smith
Hi Allen, Thanks for taking the time to read and respond. I've read your reply in detail and I feel like it deserves a point-by-point response, but I think the following might get us on the same page more quickly. The important point to consider is that I'm *not* comparing this: A.) let

Re: usable enough private names (was: Re: Using Object Literals as Classes)

2012-03-17 Thread Brendan Eich
Axel Rauschmayer wrote: private x,y; is syntactically tricky inside an object initializer. The previous consensus was to use private { x, y } I don't like object literal syntax, it takes over like a weed. If classes are worth adding with higher-level (but still desugarable) semantics

Re: usable enough private names (was: Re: Using Object Literals as Classes)

2012-03-17 Thread Axel Rauschmayer
That makes sense. One thing to look out for: Not loosing one’s mind due to subtle syntactic differences between modules, class declarations and object initializers (and possibly cascades). There needs to be consistency. But (implicit) rules such as “colon = separator is comma” and “equals =

Re: Using Object Literals as Classes

2012-03-17 Thread Herby Vojčík
Kevin Smith wrote: var Blah = BaseClass | function(){} Blah.prototype.{ a: function(){}, b: function(){} } The point I'm trying to drive home is that the above is no better (worse, in fact) from a user experience standpoint, than what I have now.

Re: Using Object Literals as Classes

2012-03-17 Thread Claus Reinke
var Blah = BaseClass | function(){} Blah.prototype.{ a: function(){}, b: function(){} } let Blah = BaseClass | function() { }.prototype.( a() {}, b() {} }.constructor.{}; 1. I don't like the imperative approximations of a declarative API. Since we're

Re: Using Object Literals as Classes

2012-03-17 Thread Claus Reinke
The example you gave produces a constructor that wraps a handful of instance method definitions along with several function declarations - which I'm arguing could just as easily be outside of that function declaration, but inside of an IIFE. There are two issues here: 1) “Private methods”

Re: Using Object Literals as Classes

2012-03-17 Thread Herby Vojčík
Claus Reinke wrote: var Blah = BaseClass | function(){} Blah.prototype.{ a: function(){}, b: function(){} } let Blah = BaseClass | function() { }.prototype.( a() {}, b() {} }.constructor.{}; 1. I don't like the imperative approximations of a declarative API. Since we're designing new

Re: Using Object Literals as Classes

2012-03-17 Thread Claus Reinke
1. I don't like the imperative approximations of a declarative API. Since we're designing new language features, approximations should not be necessary. There have been suggestions to interpret '|' declaratively, and to avoid the special case for function rhs, ie, to interpret (p | obj) simply

Re: Using Object Literals as Classes

2012-03-17 Thread Kevin Smith
Currently, | sets the [[prototype]] field of the RHS object, and -if the RHS is a function literal- also specifies the [[prototype]] field of objects generated from it. I suggest to remove that special case for function RHS. Ultimately, this is my suggestion as well. And for class

Re: Using Object Literals as Classes

2012-03-17 Thread Russell Leggett
On Mar 17, 2012, at 12:18 PM, Kevin Smith khs4...@gmail.com wrote: Currently, | sets the [[prototype]] field of the RHS object, and -if the RHS is a function literal- also specifies the [[prototype]] field of objects generated from it. I suggest to remove that special case for function RHS.

Re: Using Object Literals as Classes

2012-03-17 Thread Allen Wirfs-Brock
On Mar 16, 2012, at 11:42 PM, Kevin Smith wrote: Hi Allen, Thanks for taking the time to read and respond. I've read your reply in detail and I feel like it deserves a point-by-point response, but I think the following might get us on the same page more quickly. The important point

Re: Using Object Literals as Classes

2012-03-17 Thread Allen Wirfs-Brock
On Mar 17, 2012, at 8:39 AM, Claus Reinke wrote: 1. I don't like the imperative approximations of a declarative API. Since we're designing new language features, approximations should not be necessary. There have been suggestions to interpret '|' declaratively, and to avoid the special

Re: Using Object Literals as Classes

2012-03-17 Thread Herby Vojčík
Claus Reinke wrote: 1. I don't like the imperative approximations of a declarative API. Since we're designing new language features, approximations should not be necessary. There have been suggestions to interpret '|' declaratively, and to avoid the special case for function rhs, ie, to

Re: Using Object Literals as Classes

2012-03-17 Thread Herby Vojčík
Allen Wirfs-Brock wrote: On Mar 17, 2012, at 8:39 AM, Claus Reinke wrote: 1. I don't like the imperative approximations of a declarative API. Since we're designing new language features, approximations should not be necessary. There have been suggestions to interpret '|' declaratively, and

Re: Using Object Literals as Classes

2012-03-17 Thread Allen Wirfs-Brock
On Mar 17, 2012, at 1:20 PM, Herby Vojčík wrote: Allen Wirfs-Brock wrote: ... (function () {}) creates two object, not one. We have to set the [[Prototype]] of both objects to something. In deciding how to do this it is important to look at the role of each member of that object

Re: Using Object Literals as Classes

2012-03-17 Thread Kevin Smith
While you wouldn't use A because it can't express the full semantics of C, that doesn't mean that many users who currently have to write B wouldn't prefer to be able to write A. Yes - many (most?) users will benefit from being able to write A. But the thrust of my argument is not that there

Re: Using Object Literals as Classes

2012-03-16 Thread Herby Vojčík
Kevin Smith wrote: Rather than abuse your inbox, I published this as a blog entry: http://blog.khs4473.com/2012/03/using-object-literals-as-classes.html Summary: It has been suggested that extended object literals can be used to define class-like abstractions, and that consequently class

Re: Using Object Literals as Classes

2012-03-16 Thread David Bruant
Le 16/03/2012 17:53, Herby Vojčík a écrit : And second, it is not a tragedy if such classes leak. What do you mean exactly by leak. Like private name leaking? David ___ es-discuss mailing list es-discuss@mozilla.org

Re: Using Object Literals as Classes

2012-03-16 Thread David Bruant
Hi, I'll do a 2 parts answer. First, I'll answer the blog post, second, I'll try to take a step back and discuss composition in JavaScript. === Part I === Le 16/03/2012 17:04, Kevin Smith a écrit : Rather than abuse your inbox, I published this as a blog entry:

Re: Using Object Literals as Classes

2012-03-16 Thread Herby Vojčík
David Bruant wrote: Le 16/03/2012 17:53, Herby Vojčík a écrit : And second, it is not a tragedy if such classes leak. What do you mean exactly by leak. Like private name leaking? Some of the underlying mechanics. David ___ es-discuss mailing

Re: Using Object Literals as Classes

2012-03-16 Thread Kevin Smith
Thanks, David. First, I'd like to point out that in the blog post I'm putting on the hat of a library author (I happen to be one, but that's beside the point). One of the first conclusions that I come to (as a library author) is that the idiom described here:

Re: Using Object Literals as Classes

2012-03-16 Thread Russell Leggett
On Fri, Mar 16, 2012 at 4:26 PM, Kevin Smith khs4...@gmail.com wrote: Thanks, David. First, I'd like to point out that in the blog post I'm putting on the hat of a library author (I happen to be one, but that's beside the point). One of the first conclusions that I come to (as a library

RE: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
16, 2012 17:07 To: Kevin Smith Cc: es-discuss Subject: Re: Using Object Literals as Classes On Fri, Mar 16, 2012 at 4:26 PM, Kevin Smith khs4...@gmail.commailto:khs4...@gmail.com wrote: Thanks, David. First, I'd like to point out that in the blog post I'm putting on the hat of a library author (I

usable enough private names (was: Re: Using Object Literals as Classes)

2012-03-16 Thread Herby Vojčík
Domenic Denicola wrote: Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes (i.e. no prototype methods at all), since we value encapsulation. I can't imagine we're alone. So any class solution that doesn't fully incorporate private names (e.g. by

RE: usable enough private names (was: Re: Using Object Literals as Classes)

2012-03-16 Thread Domenic Denicola
, March 16, 2012 17:20 To: Domenic Denicola Cc: Russell Leggett; Kevin Smith; es-discuss Subject: usable enough private names (was: Re: Using Object Literals as Classes) Domenic Denicola wrote: Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes (i.e

Re: Using Object Literals as Classes

2012-03-16 Thread David Bruant
Le 16/03/2012 21:26, Kevin Smith a écrit : Thanks, David. First, I'd like to point out that in the blog post I'm putting on the hat of a library author (I happen to be one, but that's beside the point). One of the first conclusions that I come to (as a library author) is that the idiom

Re: Using Object Literals as Classes

2012-03-16 Thread Rick Waldron
On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola dome...@domenicdenicola.com wrote: Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes (i.e. no prototype methods at all), since we value encapsulation. I can't imagine we're alone. For my own

Re: Using Object Literals as Classes

2012-03-16 Thread David Bruant
Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola dome...@domenicdenicola.com mailto:dome...@domenicdenicola.com wrote: Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes (i.e. no

Re: Using Object Literals as Classes

2012-03-16 Thread Rick Waldron
On Fri, Mar 16, 2012 at 6:04 PM, David Bruant bruan...@gmail.com wrote: Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola dome...@domenicdenicola.com wrote: Just to contribute to this... er... fun-thread... My team uses the closure pattern

Re: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
On Mar 16, 2012, at 18:05, David Bruant bruan...@gmail.commailto:bruan...@gmail.com wrote: Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola dome...@domenicdenicola.commailto:dome...@domenicdenicola.com wrote: Just to contribute to this... er...

Re: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
On Mar 16, 2012, at 18:12, Rick Waldron waldron.r...@gmail.commailto:waldron.r...@gmail.com wrote: On Fri, Mar 16, 2012 at 6:04 PM, David Bruant bruan...@gmail.commailto:bruan...@gmail.com wrote: Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola

Re: Using Object Literals as Classes

2012-03-16 Thread David Bruant
Le 16/03/2012 23:12, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 6:04 PM, David Bruant bruan...@gmail.com mailto:bruan...@gmail.com wrote: Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar 16, 2012 at 5:12 PM, Domenic Denicola dome...@domenicdenicola.com

Re: Using Object Literals as Classes

2012-03-16 Thread John J Barton
On Fri, Mar 16, 2012 at 3:04 PM, David Bruant bruan...@gmail.com wrote: Unfortunately, methods on prototype require to have properties that are public. If you avoid prototype methods, all your attributes and private methods can be shared by public method scopes. I think you are mixing up

Re: Using Object Literals as Classes

2012-03-16 Thread Axel Rauschmayer
Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes (i.e. no prototype methods at all), since we value encapsulation. I can't imagine we're alone. Do you see privacy via closures and prototypes as mutually exclusive? In my experience, they

Re: Using Object Literals as Classes

2012-03-16 Thread Rick Waldron
On Fri, Mar 16, 2012 at 6:20 PM, Domenic Denicola dome...@domenicdenicola.com wrote: On Mar 16, 2012, at 18:12, Rick Waldron waldron.r...@gmail.com wrote: On Fri, Mar 16, 2012 at 6:04 PM, David Bruant bruan...@gmail.com wrote: Le 16/03/2012 23:00, Rick Waldron a écrit : On Fri, Mar

RE: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
From: Rick Waldron [mailto:waldron.r...@gmail.com] Sent: Friday, March 16, 2012 18:40 To: Domenic Denicola Cc: David Bruant; es-discuss Subject: Re: Using Object Literals as Classes On Fri, Mar 16, 2012 at 6:20 PM, Domenic Denicola dome...@domenicdenicola.commailto:dome...@domenicdenicola.com

RE: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
From: Axel Rauschmayer [mailto:a...@rauschma.de] Sent: Friday, March 16, 2012 18:35 To: Domenic Denicola Cc: Russell Leggett; Kevin Smith; es-discuss Subject: Re: Using Object Literals as Classes Just to contribute to this... er... fun-thread... My team uses the closure pattern for our classes

Re: Using Object Literals as Classes

2012-03-16 Thread Rick Waldron
On Mar 16, 2012, at 7:11 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: Rick Waldron [mailto:waldron.r...@gmail.com] Sent: Friday, March 16, 2012 18:40 To: Domenic Denicola Cc: David Bruant; es-discuss Subject: Re: Using Object Literals as Classes On Fri, Mar

Re: Using Object Literals as Classes

2012-03-16 Thread Tab Atkins Jr.
On Fri, Mar 16, 2012 at 4:23 PM, Domenic Denicola dome...@domenicdenicola.com wrote: In theory I see them as complementary, but in practice I have never been able to integrate prototypes. Consider: a method can only be attached to a prototype if it needs access to an instance’s public state

RE: Using Object Literals as Classes

2012-03-16 Thread Domenic Denicola
From: Rick Waldron [mailto:waldron.r...@gmail.com] Sent: Friday, March 16, 2012 19:28 To: Domenic Denicola Cc: David Bruant; es-discuss Subject: Re: Using Object Literals as Classes On Mar 16, 2012, at 7:11 PM, Domenic Denicola dome...@domenicdenicola.commailto:dome...@domenicdenicola.com wrote

Re: Using Object Literals as Classes

2012-03-16 Thread Rick Waldron
On Mar 16, 2012, at 7:37 PM, Domenic Denicola dome...@domenicdenicola.com wrote: From: Rick Waldron [mailto:waldron.r...@gmail.com] Sent: Friday, March 16, 2012 19:28 To: Domenic Denicola Cc: David Bruant; es-discuss Subject: Re: Using Object Literals as Classes On Mar 16, 2012

Re: Using Object Literals as Classes

2012-03-16 Thread Kevin Smith
var Blah = BaseClass | function(){} Blah.prototype.{ a: function(){}, b: function(){} } The point I'm trying to drive home is that the above is no better (worse, in fact) from a user experience standpoint, than what I have now. To be blunt, I would not use the above

Re: Using Object Literals as Classes

2012-03-16 Thread Allen Wirfs-Brock
Kevin, Thanks for taking the time to write up your thoughts[1] in this area. I won't try to make a point by point response because I think others on this list are already doing a good job at this. However, I do what do clarify a few points about the intent and likely usage patterns of of

Re: Using Object Literals as Classes

2012-03-16 Thread Allen Wirfs-Brock
On Mar 16, 2012, at 6:05 PM, Kevin Smith wrote: var Blah = BaseClass | function(){} Blah.prototype.{ a: function(){}, b: function(){} } The point I'm trying to drive home is that the above is no better (worse, in fact) from a user experience standpoint, than what I

Re: Using Object Literals as Classes

2012-03-16 Thread John J Barton
On Fri, Mar 16, 2012 at 6:28 PM, Allen Wirfs-Brock al...@wirfs-brock.com wrote: On this point, I probably should define what I mean by declarative.  I consider code to be declarative, if a human (or an appropriately programmed machine) can understand its meaning without actually (or

Re: usable enough private names (was: Re: Using Object Literals as Classes)

2012-03-16 Thread Axel Rauschmayer
private x,y; is syntactically tricky inside an object initializer. The previous consensus was to use private { x, y } For example here: https://gist.github.com/1332193 (Brendan’s class proposal) https://gist.github.com/1336846 (my class proposal) On Mar 16, 2012, at 22:24 , Domenic