Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Created November 28, 2012 18:22
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WebReflection/4163041 to your computer and use it in GitHub Desktop.
Save WebReflection/4163041 to your computer and use it in GitHub Desktop.
Cross ECMAScript way to know if an object is an Arguments one. IE5+ and every other old or modern engine should simply work.
var isArguments = function(toString){
// (C) WebReflection - Mit Style License
var compare = toString.call(arguments);
return ~compare.indexOf("Arguments") ?
function isArguments(object) {
return toString.call(object) == compare;
} :
(compare = toString.call([])) &&
function isArguments(object) {
try {
return toString.apply(
object, object
) != compare;
} catch(o_O) {
return false;
}
}
;
}({}.toString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment