Skip to content

Instantly share code, notes, and snippets.

@davidblurton
Last active January 3, 2016 21:19
Show Gist options
  • Save davidblurton/8520944 to your computer and use it in GitHub Desktop.
Save davidblurton/8520944 to your computer and use it in GitHub Desktop.
Call and apply examples
Array.prototype.max = function() {
return Math.max.apply(Math, this);
};
[1,2,3].max(); // => 3
Array.prototype.all = function() {
return [].every.apply(this, [].slice.call(arguments));
};
[1,2,3].all(function(x) {
return x > 0;
}); // => true
Array.prototype.tail = function() {
return [].slice.call(this, 1);
};
[1,2,3].tail(); // => [2, 3]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment