Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

prototype

The prototype property is used to implement inheritance and shared properties among objects. It is available for use with many objects in JavaScript since they are descendants of the Object object.

Common scenarios for usage include:
  • Adding new shared properties/methods to objects.
  • Overriding and replacing an object's properties/methods.
  • Working with custom objects and class-like code structures.
  • Object inheritance.
Syntaxobject.prototype

Examples

Adding a new shared method to an object

Array.prototype.average = function() { var sum = 0, avg, i = 0; for( i; i < this.length; i++ ){ sum += this[i]; } avg = sum / this.length; return avg; } var values = [ 98, 82, 70, 91 ]; alert( values.average() ); Overwriting and replacing an object's existing properties/methods: ... Object inheritance: ...

JavaScript

Properties

bodycalleeclosedcookiedocumentdropEffecteffectAllowedfilesframeElementframeshistoryInfinityinnerHeightinnerHTMLinnerWidthlengthlocationlocationbarnameNaNnavigatornullopenerouterHeightparentprototypescreenstatetextContentundefined