5.1. Conventions Used

Since JavaScript is a largely untyped language, it has no syntax for specifying the type of its identifiers. Since Prototype has many aspects that are functional in nature, we will use the following ad hoc syntax to denote types.

A type declaration is a qualified name followed by a type:

            <type-decl> ::= <name>::<type>                  // underlining denotes static
member

Where a type is one of the following:

<type> ::= number                               // a primitive number
         | string                               // a primitive string
         | boolean                              // a primitive boolean
         | undefined                            // undefined (void)
         | Function()               -> <type>   // a function taking no arguments
         | Function(
            <arg>(,
            <arg>)*) -> <type>   // a function taking
N arguments
         | Constructor()                        // a constructor taking no arguments
         | Constructor(
            <arg>
            (,
            <arg>)*)          // a constructor taking
N arguments
         | (
            <type>
            )                             // a bracketed type for clarity
         | any                                  // a wild card
         | <class-name>[of <type>]              // a class e.g. Array

<arg> ::= [<name>
            ::]<type> | (
            <arg>
            )            // a named type or
bracketed argument

Get Prototype and Scriptaculous: Taking the Pain out of JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.