Last active
January 3, 2016 21:19
-
-
Save davidblurton/8520944 to your computer and use it in GitHub Desktop.
Call and apply examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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