Skip to content

Instantly share code, notes, and snippets.

@g8up
Created April 21, 2016 17:29
Show Gist options
  • Save g8up/b9273ff7366eaf283d2bb54dd54f4872 to your computer and use it in GitHub Desktop.
Save g8up/b9273ff7366eaf283d2bb54dd54f4872 to your computer and use it in GitHub Desktop.
验证数据类型
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
@g8up
Copy link
Author

g8up commented Apr 25, 2016

toString.call( document.querySelectorAll('a') )
"[object NodeList]"

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