Sep 27 meeting notes

Oliver Hunt oliver at apple.com
Fri Sep 30 12:09:29 PDT 2011


On Sep 30, 2011, at 11:53 AM, Brendan Eich wrote:

> On Sep 30, 2011, at 7:57 PM, Erik Arvidsson wrote:
> 
>> One of the things I like about the object literal syntax is that it
>> doesn't seem like things might be in scope. Take this example (with
>> intentional error):
>> 
>> class Point {
>>  var x = 0;
>>  var y = 0;
>>  distance(other) {
>>    return Math.sqrt(x * other.x + y * other.y);
>>  }
>> }
>> 
>> it is very tempting to think that var x and var y are in scope. If an
>> object literal is used at least we have the current behavior to steer
>> people into doing the right thing.
> 
> Two thoughts:
> 
> 1. Oliver and others do want x and y to be in scope somehow. They can't be via the |this| parameter object on the scope chain, though. That's dynamic scope (the prototype is extensible, or *a* prototype, possibly Object.prototype, is). But the desire to avoid this. prefixing is natural and predictable for people coming from C++, Java, etc. Should we consider supporting this expectation somehow, rather than steering people away from it with less natural syntax?

My recent proposals have not been placing member fields in scope (all my examples use this.blah), they have merely been providing a declarative syntax to define the shape of an instance of the object.  Basically i've started leaning towards python-esque classes, with optional declarative field syntax (which also has the benefit of saving you from the setter on the prototype trap that you suffer when not using object literals).

I also see the constructor(this.x, ..) stuff as syntactic sugar that is unrelated to the actual class semantics -- that syntax could be added at a later date and would not impact the behaviour of classes, and if it were added i see no reason to restrict it solely "constructors".  That said I don't like the syntax at all :D

--Oliver

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110930/18af27e4/attachment.html>


More information about the es-discuss mailing list