Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
36
Task/Function-prototype/JavaScript/function-prototype-1.js
Normal file
36
Task/Function-prototype/JavaScript/function-prototype-1.js
Normal 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
|
||||
37
Task/Function-prototype/JavaScript/function-prototype-2.js
Normal file
37
Task/Function-prototype/JavaScript/function-prototype-2.js
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue