Skip to content

Instantly share code, notes, and snippets.

@kflorence
Forked from rkatic/isArguments.js
Created May 2, 2011 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kflorence/952521 to your computer and use it in GitHub Desktop.
Save kflorence/952521 to your computer and use it in GitHub Desktop.
isArguments
var isArguments = (function( undefined ) {
var toString = Object.prototype.toString,
returnTrue = function() {
return arguments !== undefined;
};
return function( obj ) {
if ( obj != null ) {
if ( toString.call( obj ) == "[object Arguments]" ) {
return true;
} else if ( "callee" in obj ) {
try {
return returnTrue.apply( this, obj );
} catch ( e ) {}
}
}
return false;
}
})();
@rkatic
Copy link

rkatic commented May 2, 2011

The obj != null check have to be even before toSting.call.

Btw. seams cls is superfluous in your case.

@kflorence
Copy link
Author

Hmm, I thought so too but it seems to work in the else if -- good call on the cls. null/undefined seem to return [object Window].

@rkatic
Copy link

rkatic commented May 2, 2011

You are right about null/undefined returning [object Window], but note that in strict mode it will throw an exception.

@kflorence
Copy link
Author

Yeah, I should be strict mode compliant. Also I was happy to see [object Null] and [object Undefined] in FF 4.0, that could be helpful.

@rkatic
Copy link

rkatic commented May 2, 2011

Yea, seams I was wrong on that. Hope other browsers are same...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment