January 2012
1 post
6 tags
JavaScript: prototype property
In JavaScript, prototype is a property of functions which easily allows for object extension and inheritance.
var x = {};
x.prototype; // undefined
x = [];
x.prototype; // undefined
x = function(){};
x.prototype; // Object
To extend an object with prototype:
Array.prototype.add = function() {
var length = this.length;
var sum = 0;
for (var i = 0; i < length; i++) {
if...