Created
April 21, 2016 17:29
-
-
Save g8up/b9273ff7366eaf283d2bb54dd54f4872 to your computer and use it in GitHub Desktop.
验证数据类型
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
function isType( type ){ | |
return function( val ){ | |
return toString.call( val ) === '[object ' + type + ']'; | |
}; | |
} | |
['Object', 'Array', 'Number', 'Window'].forEach(function( type ){ | |
window['is'+ type ] = isType( type ); | |
}); | |
isArray('');// false | |
isNumber( 1 ); //true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
toString.call( document.querySelectorAll('a') )
"[object NodeList]"