Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Last active August 29, 2015 14:08
Show Gist options
  • Save johnathan-sewell/237be0b78cd909dd3794 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/237be0b78cd909dd3794 to your computer and use it in GitHub Desktop.
Interesting JavaScript tricks
/* 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