9.6.2 - 'this' or 'super' in a static method

Garrett Smith dhtmlkitchen at gmail.com
Mon Aug 20 14:14:11 PDT 2007


In ES3, i use this in context of a function instance.

A = function A () {

}
A.instances = { };
A.getById = function getById( id ) {
  return ( this.instances.hasOwnProperty( id ) && this.instances[ id ] ) ||
    ( this.instances[ id ] = new this( id ) );
};

static this?

On 8/19/07, Peter Hall <peter.hall at memorphic.com> wrote:
> On 8/17/07, Garrett Smith <dhtmlkitchen at gmail.com> wrote:
> > 9.6.2 It is an error for the 'this' or 'super' expression to appear in
> > the body of a static method.
> >
> > 1. Is this error mentioned a compile-time error?
>
> Compile-time. In general, any error that can be detected at
> compile-time is a compile-time error.
>
> > 2. Why does 'this' in a static method generate an error? (it shouldn't
> > refer to the class?)
>
> 'this' always refers to an instance. Inside a class, it would be
> confusing if 'this' refers sometimes to the instance and sometimes to
> the class, depending on one attribute of the containing method.
>
> Cormac, could the Self Proposal be extended here to allow 'Self' (or
> my preference, 'this type') to refer to the class in this context?
>
>
> Peter
>


-- 
http://dhtmlkitchen.com/



More information about the Es4-discuss mailing list