What are javascript prototypes? (short answer for advanced javascripters)

[I’ve also written a longer answer for beginners] 

Prototypes can extend any class you want by adding a property or a method. By calling,

[source:javascript]
String.prototype.alertMe = function() {
alert(this);
}
[/source]

you are adding the method alertMe() to every String object of your application.

It uses less memory because javascript creates only one instance of the function and uses references to it.

Short answer done!

Post a comment

Comments are moderated and innapropriate ones won't be approved. Please respect this public space.