O'Reilly logo

Prototype and Scriptaculous: Taking the Pain out of JavaScript by Chris Angus

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required