Anonymous user
Function prototype: Difference between revisions
Improved examples (look less like a Java knock-off)
(Omit from Déjà Vu) |
(Improved examples (look less like a Java knock-off)) |
||
Line 313:
=={{header|JavaScript}}==
JavaScript does use function prototypes, it doesn't care the type of function, only that it is indeed a function.
<lang JavaScript>
ents
function List() {}
List.prototype.push = function() {
[].push.apply(this, arguments);
return this.length;
};
List.prototype.pop = function() {
return [].pop.call(this);
};
var l = new List();
l.push(5);
l.length; // 1
l[0]; 5
l.pop(); // 5
l.length; // 0
// A prototype declaration for a function that utilizes varargs
function List() {
this.push.apply(this, arguments);
}
List.prototype.push = function() {
[].push.apply(this, arguments);
return this.length;
};
List.prototype.pop = function() {
return [].pop.call(this);
};
var l = new List(5, 10, 15);
l.length; // 3
l[0]; 5
l.pop(); // 15
l.length; // 2
</lang>
=={{header|PARI/GP}}==
|