-
-
Save kflorence/952521 to your computer and use it in GitHub Desktop.
isArguments
This file contains 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
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; | |
} | |
})(); |
You are right about null/undefined returning [object Window], but note that in strict mode it will throw an exception.
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.
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
Hmm, I thought so too but it seems to work in the
else if
-- good call on thecls
. null/undefined seem to return [object Window].