Sometimes you just want to extend javascript with some “home made” functionality.
Prototyping (this has NOTHING to do with prototypejs framework!)
is like attaching custom methods to objects allready created,
in which all object instances then instantly share.

For example we want to have a function called count() for the Array() object,
that counts all the elements of an array and returns it.

//object.prototype.newFunctionName
//in the function: "this" is the Array object
//so this[0] would be 'hello'
Array.prototype.count = function() {
	return this.length;
};

var myArray = [ 'hello', 'some', 'another', 'element'];

alert(myArray.count() );

This comes in very handy because you can make your own javascript add-ons.
(continue reading…)