Just sort of curious... Given the following:

// old and busted
function SomeClass() {}; SomeClass.prototype.someMethod = function(arg) {
... }

// new hotness
class SomeClass { someMethod(arg) { ... } }

In the second form, how would I denote a method that is defined as an own
property? Additionally, how would something like the following be handled?

function Ctor() {
    this.method = function() {
        return "own property";
    };
    return this;
}

Ctor.prototype.method = function() {
    return "instance property";
};

var c = new Ctor();

console.log(
    c.method() // "own property"
);

Thanks in advance :)

Rick



On Wed, May 18, 2011 at 3:10 PM, Bob Nystrom <rnyst...@google.com> wrote:

> On Wed, May 18, 2011 at 11:48 AM, Brendan Eich <bren...@mozilla.com>wrote:
>
>> The whole of class declaration is a mouthful. 'function' and 'prototype'
>> are overlong too.
>>
>
> Agreed. One of the reasons I'm really excited about this proposal is that
> it addresses those:
>
> // old and busted
> function SomeClass() {}; SomeClass.prototype.someMethod = function(arg) {
> ... }
>
> // new hotness
> class SomeClass { someMethod(arg) { ... } }
>
>
> We can try for conciseness in this one corner but it doesn't help in
>> general. I think we need to weight the whole syntax and see where the
>> verbosity *and other* pain points are in practice.
>>
>
> Sure. I'm not stuck on "new", but in the chunks of sample code I've put
> together using "constructor" (which is what Traceur uses/did use for a good
> while) it did actually stick out as a syntactic wart, at least to me.
>
> Same with 'constructor', and that property must exist somehow. Why not be
>> explicit and avoid having two names for one prototype property?
>>
>> 3 is false in ES5. Reserved identifiers are valid property names. This is
>> implemented in all the ES5-supporting browsers.
>>
>
> Ah, my mistake. These are both fair points. It's too bad "constructor" is
> such a long word.
>
> In the interests of considering all possibilities, one option would be to
> use no name at all for the constructor:
>
> class Point {
>   (x, y) {
>     this.x = x;
>     this.y = y;
>   }
> }
>
> I find that simultaneously delightfully lightweight and terrifyingly
> obscure.
>
> - bob
>
>
> _______________________________________________
> 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

Reply via email to