Last active
August 29, 2015 14:08
-
-
Save johnathan-sewell/237be0b78cd909dd3794 to your computer and use it in GitHub Desktop.
Interesting JavaScript tricks
This file contains hidden or 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
/* Get an Array from arguments | |
arguments does not have a prototype link to Array.prototype, it's just array-like | |
(it has a length property). Use slice to get an array from arguments. | |
The slice() method returns a shallow copy of a portion of an array into a new array object. | |
arr.slice([begin[, end]]) | |
*/ | |
function duckCount() { | |
return Array.prototype.slice.call(arguments).filter(function(obj) { | |
return Object.prototype.hasOwnProperty.call(obj, 'quack') | |
}).length | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment