src code

namespace Prototype

Description

The Prototype namespace provides fundamental information about the Prototype library you're using, as well as a central repository for default iterators or functions.

We say "namespace," because the Prototype object is not intended for instantiation, nor for mixing in other objects. It's really just... a namespace.

Your version of Prototype

Your scripts can check against a particular version of Prototype by examining Prototype.Version, which is a version String (e.g. "<%= PROTOTYPE_VERSION %>"). The famous script.aculo.us library does this at load time to ensure it's being used with a reasonably recent version of Prototype, for instance.

Browser features

Prototype also provides a (nascent) repository of browser feature information, which it then uses here and there in its source code. The idea is, first, to make Prototype's source code more readable; and second, to centralize whatever scripting trickery might be necessary to detect the browser feature, in order to ease maintenance.

Default iterators and functions

Numerous methods in Prototype objects (most notably the Enumerable module) let the user pass in a custom iterator, but make it optional by defaulting to an "identity function" (an iterator that just returns its argument, untouched). This is the Prototype.K function, which you'll see referred to in many places.

Many methods also take it easy by protecting themselves against missing methods here and there, reverting to empty functions when a supposedly available method is missing. Such a function simply ignores its potential arguments, and does nothing whatsoever (which is, oddly enough, blazing fast). The quintessential empty function sits, unsurprisingly, at Prototype.emptyFunction (note the lowercase first letter).

Namespaces

  • Prototype.Selector

    A namespace that acts as a wrapper around the choosen selector engine (Sizzle by default).

  • Prototype.Browser

    A collection of Boolean values indicating the browser which is currently in use. Available properties are IE, Opera, WebKit, MobileSafari and Gecko.

  • Prototype.BrowserFeatures

    A collection of Boolean values indicating the presence of specific browser features.

Class methods

Class properties