Skip to content

Instantly share code, notes, and snippets.

@SiZapPaaiGwat
Forked from rkatic/isArguments.js
Last active August 29, 2015 14:18
Show Gist options
  • Save SiZapPaaiGwat/f254afb6998dfcddb0d7 to your computer and use it in GitHub Desktop.
Save SiZapPaaiGwat/f254afb6998dfcddb0d7 to your computer and use it in GitHub Desktop.
// Cross-browser but not absolutely strong.
function isArguments( obj ) {
return typeof obj === "object" && ( "callee" in obj ) && typeof obj.length === "number";
}
// Ideally strong, but broken on Opera...
var isArguments = (function( undefined ) {
var toStr = ({}).toString,
returnTrue = function() {
// To be sure it will not be inlined (future engines).
return arguments !== undefined;
},
test = function( obj ) {
return obj != null && toStr.call( obj ) === "[object Arguments]";
};
return test( arguments ) ? test :
function( obj ) {
// Using "in" works in strict mode too.
if ( obj != null && "callee" in obj ) {
try {
return returnTrue.apply( this, obj );
} catch (e) {}
}
return false;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment