1 Déterminer s'il s'agit d'un type de tableau
Copiez le code comme suit :
<STRONG><script type="text/javascript">
//<![CDONNEES[
var a=[0];
document.write(isArray(a),'<br/>');
la fonction estArray(obj){
return (typeof obj=='object')&&obj.constructor==Array;
}
//]]>
</script></STRONG>
2 Déterminer s'il s'agit d'un type de chaîne
Copiez le code comme suit :
<script type="text/javascript">
//<![CDONNEES[
document.write(isString('test'),'<br/>');
document.write(isString(10),'<br/>');
fonction isString(str){
return (typeof str=='string')&&str.constructor==String;
}
//]]>
</script>
3 Déterminez s'il s'agit d'un type numérique
Copiez le code comme suit :
<script type="text/javascript">
//<![CDONNEES[
document.write(isNumber('test'),'<br/>');
document.write(isNumber(10),'<br/>');
la fonction estNombre(obj){
return (typeof obj=='number')&&obj.constructor==Number;
}
//]]>
</script>
4 Déterminez s'il s'agit d'un type de date
Copiez le code comme suit :
<script type="text/javascript">
//<![CDONNEES[
document.write(isDate(new Date()),'<br/>');
document.write(isDate(10),'<br/>');
fonction estDate(obj){
return (typeof obj=='object')&&obj.constructor==Date;
}
//]]>
</script>
5 Déterminer s'il s'agit d'une fonction
Copiez le code comme suit :
<script type="text/javascript">
//<![CDONNEES[
document.write(isFunction(function test(){}),'<br/>');
document.write(isFunction(10),'<br/>');
la fonction estFonction(obj){
return (typeof obj=='function')&&obj.constructor==Function;
}
//]]>
</script>
6 Déterminer s'il s'agit d'un objet
Copiez le code comme suit :
<script type="text/javascript">
linum
//<![CDONNEES[
document.write(isObject(new Object()),'<br/>');
document.write(isObject(10),'<br/>');
fonction estObjet(obj){
return (typeof obj=='object')&&obj.constructor==Object;
}
//]]>
</script>