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. “1.5.0”). The famous 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.

The only currently available feature detection is browser support for DOM Level 3 XPath, accessible as a boolean at Prototype.BrowserFeatures.XPath.

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).



K(argument) -> argument

K is Prototype’s very own identity function, i.e. it returns its argument untouched.



The emptyFunction does nothing… and returns nothing!