Dmitry Soshnikov dmitry.soshnikov at gmail.com
Thu Nov 17 06:41:35 PST 2011

On 17.11.2011 18:10, David Herman wrote:
> On Nov 17, 2011, at 5:16 AM, Dmitry Soshnikov wrote:
>>> And `extends` fails completely as the syntax.
>> This is why it's so wide-spread in other languages for inheritance, 
>> right? ;)
> In other languages it's not a stand-alone operator but a part of class 
> syntax. (I don't know Ruby, so maybe you'll correct me there.)

True about that `extends' is limited only for classes in other langs 
(except Scala, e.g. -- that's mentioned, it may extend objects as well 
and this is I propose for ES also).

About Ruby: it uses < for inheritance of classes, e.g.:

class Foo < Bar

And uses `.extend' instance method (inherited from Object) for 
imperative delegation-based mixing. A module can be mixed to a simple 

module Foo
   def bar
     print "Hello"

x = {}

x.bar() # "Hello"

Thus, notice, it's exactly delegation-based inheritance -- if I change 
the method in the module Foo (e.g. redefine the `bar' method), the 
changes are reflected on the `x' object.

As a historical note: Prototype.js borrowed this `Object.extend' from 
Ruby. Though, they placed it into the Object, not into the 
`Object.prototype' since hadn't control of enumerable attribute. Also 
they made own proprieties copying, but not delegation inheritance. The 
reason -- they couldn't. But if the could, very likely we would have the 
same implementation in JS libs as in Ruby.

Anyway, Ruby is not on the list, so sorry everyone for diverting your 
attention from ES. Let's back to it.

>> `extends' is here for years in many langs for exactly to chain an 
>> object with its prototype or class (the langs which first come in 
>> mind are: Java, PHP, Scala, CoffeeScript, Dart, others). It's not 
>> used to copy own properties!
>> *As well*, as it's not used to copy own properties in Ruby (in case 
>> if you want to argue with that Object.extend copies own properties in 
>> JS libs)! -- exactly from there was borrowed Object.extend to 
>> Prototype.js. In Ruby it just /chains/ an object with yet another 
>> "prototype" (hidden meta-class which inherits from mixin module).
>> So `extends' is for inheritance. And was even reserved in ES.
> I've never had a problem with using `extends` as part of a `class` 
> syntax. There's no need for `extends` to stand on its on.

OK, though, I'd like again to notice Scala:

object foo extends bar {

class Foo extends bar {

the same I proposed to ES (to avoid new keyword `object' I used simple 
`let' or `var'):

let foo extends bar {
   x: 100

Is equivalence of:

let foo = Object.create(bar, {x: {value: 100}});

And as I understand correctly it syntactically differs from your 
proposed `with' only in:

let foo = bar with {
   x: 100

and I like it. It really reflects the essence. As well as `extends' 
above as I see.

Thus, answering your mail (sorry for not answered before), I can't say, 
whether `extends' is infix or prefix. I don't completely understood on 
"can be conditional keywords", but what prevents `extends' to be the same?

>> Hope I made it more clear.
> Sorry I misunderstood which syntax you were promoting (prefix rather 
> than infix). I explained in my reply to Russ why I think it doesn't work.

I didn't understand myself yet which syntax I'd like to see 
_technically_. I know that I like it visually. Well, as well as with `with'.


>> Once again (sorry, Axel Rauschmayer, you may skip this phrase ;)), 
>> I'm not against `with', I'm just worry about that it had/has diff. 
>> semantics. But. We may re-use it for mixins.
> I'm not sure how much I agree with your argument about confusion with 
> the old semantics. Re: "once again" -- I *did* reply to that point 
> last night, and you didn't reply to that. But maybe my answer was too 
> cute. To elaborate:
> On the one hand: for JS programmers who already know the language, I 
> don't think it's that confusing to learn that `with` statements were 
> banned and now there's a new `with` expression. For newbies, they 
> arguably don't have to learn the old form, so there's nothing to confuse.
> On the other hand: there is the fact that ES3 and non-strict ES5 code 
> will exist indefinitely into the future, so when reading code, people 
> would probably end up having to disambiguate what they're looking at 
> based on the language version. That's a valid concern.
> I also agree that `with` fits very well as future syntax for mixins or 
> traits, and that's a direction we ought to work towards (post-ES6). 
> And it might also be confusing to use `with` as both a part of the 
> class syntax *and* an expression operator.
> As I say, I'm not sure how much I agree, but they're valid concerns.
> Dave

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

More information about the es-discuss mailing list