April 2002 Draft
JavaScript 2.0
Core Language
Interfaces
previousupnext

Wednesday, December 5, 2001

Interface Definition

InterfaceDefinition 
   interface Identifier ExtendsList Block
|  interface Identifier Semicolon
ExtendsList 
   «empty»
|  extends TypeExpressionList
TypeExpressionList 
   TypeExpressionallowIn

Interfaces behave much like classes except that an interface I is not a supertype of a class C that implements I. Instead, an instance c of C may be implicitly coerced to type I, which creates an instance i of I. Implicitly coercing i to type C yields the original instance c. It is unspecified whether c == i.

An interface may have both concrete and abstract members, but it may not have constructors.

In the absence of name conflicts, an interface I’s members may be accessed as properties of any instance c of a class C that implements I. However, it is legal to define an interface I with a member m with the same name as a member of class C and yet have the two members be different. It is also legal for a class to implement two interfaces I and J both of which have a member named m and have the two m’s remain distinct. Which one gets extracted when one performs the property lookup operation c.m depends on whether c was last coerced to one of the interfaces or to an object type.


Waldemar Horwat
Last modified Wednesday, December 5, 2001
previousupnext