ECMAScript Modularity SubGroup Meeting
Redmond, 26th March 1999

Plan for the day

Propose that we work as a group to jointly create a report as we go along today.

Intended Users

Joe Public

Intended Users

Script Hackers

Towards agreement on Least-common Denominator

Can we approach the design of ECMAScript 2 by working on the features of:

What kinds of things you want to do

Waldemar's example:


a = ((x+y)[z])(p, q, x).z;

which could be factored into


var f=(x+y)[z];

a = f(p, q, f).z

This kind of factoring should be possible. In C++ if f is given too general a type, the compiler will warn you that the second statement is in error.

All types for which knowledge of which might make a difference to the expression can be expressed in the type expressions of the language.


class C

{

   field m;

}



// should be able to create another class with a field called M.

new style classes should be accessible by old-style code with out having to restructure the old code. It would be unacceptable to limit old code to accessing only ad hoc properties.

Achieving this compatibility shouldn't force you to give up the benefits of classes etc.

Applications

What do we want to achieve with the standard?

Foundations

Packages

What goes inside a class?

Some concerns to be addressed, e.g. syntax.

classes and static initialization

Streaming Model

Syntax of Declarations

Optional Arguments and Type Annotations

What is an instance?

Herman writes an example. What does the following say about foo?

f = new foo()

Waldemar proposes we keep the same syntax as now. Herman asks what will typeof return when applied to f.

Perhaps the programmer started with:

function foo( )

and decided to change the code to define foo as:

class foo

{

}

typeof on f would now return foo rather than object

Herman now asks:

f instanceof Object

what about:

f.valueOf()

Waldemar asserts all objects are instances of Object. When applicable new objects support the same things as old ones.

Where is the prototype chain etc. for new kinds of objects?

f = new foo()



bar.prototype = f;



bar.prototype = foo;

Waldemar writes up:


class foo

{

   method m()

   {

   }



   slot a;

}



f = new foo();  // foo has a method m



function bar()

{

  ...

}



bar.prototype = f;



var g = new bar();



var foo x;



// the following generate errors

x = g;  // g is of type f not foo

g.m();  // f doesn't define m()



// but this works (why?)

g.a; // value of slot a of foo

Herman wonders why don't we take a leaf out of Java's book.


class foo

{

 ...

}



x = foo.class;  // the class object for foo

x = foo;        // the prototype of foo

The above deals with prototype based instances of new style classes. How valuable is this? Do we want to punt, if so where?

We agree that there is something worth exploring here. Can we find a solution that fits existing the expectations of existing users. Herman wonders about package private/public default and how that effects this topic.

Herman will write up a detailed proposal for review at the April meeting.

Restricting access to non-publics to this object


class X

{

   private field y;



   method m(x)

   {

      // any reference to y must be

      // to the private field y

      x.y;

   }

}

Most people find this rule to surprising. It would be too hard to sell to users.

Dave offers an alternative whereby the programmer annotates the reference to make the access explicit:


class Foo

{



   private var f;



   method m (x)

   {

      x.Foo::f   // refers to local f

   }

}

Another possibility is to use a cast, e.g.

((Foo)x).f

Rok proposes we adopt Herman's suggestion that references to other objects from untyped variables is restricted to publics unless there is an annotation such as one of the above two choices, or you are using a statically typed variable.

The consequence of this is that adding the annotation can change whether you get the private field of some object or the public field of its base class.


class Foo extends Bar

{

    public var f;

}



class Bar

{

    private var f



    method m()

    {

        Foo y = new Foo();



        y.f;         // Foo::f

        y.Bar::f;    // Bar::f

        ((Bar)y).f;  // Bar::f

    }

}



Package Protected

The End