March 2014 update

This commit is contained in:
Ingy döt Net 2014-04-02 16:56:35 +00:00
parent 09687c4926
commit a25938f123
1846 changed files with 21876 additions and 5203 deletions

View file

@ -0,0 +1,36 @@
// A prototype declaration for a function that does not require arguments
function List() {}
List.prototype.push = function() {
return [].push.apply(this, arguments);
};
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() {
return [].push.apply(this, arguments);
};
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

View file

@ -0,0 +1,37 @@
// A prototype declaration for a function that does not require arguments
class List {
push() {
return [].push.apply(this, arguments);
}
pop() {
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
class List {
constructor(...args) {
this.push(...args);
}
push() {
return [].push.apply(this, arguments);
}
pop() {
return [].pop.call(this);
}
}
var l = new List(5, 10, 15);
l.length; // 3
l[0]; 5
l.pop(); // 15
l.length; // 2

View file

@ -1,4 +0,0 @@
var randomFunction=function(a){this.someNumber=a;}; //Doesn't matter when the function uses parameters, named arguments, no arguments, or if it doesn't return nothing at all.
randomFunction.prototype.getSomeNumber=function(){return this.someNumber;}
randomFunction.prototype.setSomeNumber=function(a){return this.someNumber=a;}//editing prototype explicitly
(new randomFunction(7)).getSomeNumber();//7