Home > Web Front-end > JS Tutorial > JavaScript simple and efficient judgment of data type series functions By shawl.qiu_javascript skills

JavaScript simple and efficient judgment of data type series functions By shawl.qiu_javascript skills

WBOY
Release: 2016-05-16 19:17:59
Original
1169 people have browsed it

Note:
When I almost mastered ASP VBScript some time ago, I switched to learning Javascript/Jscript, mainly Jscript.
However, there is basically no difference between the two. The only difference is that Jscript does not have a client. Concept.

At the beginning, I found that many practical functions of VBS were not available in JS, such as formatNumber, isArray, isDate, etc.
The date object is also very strange, and cannot be directly added, subtracted or subtracted. , you need to set***...

But when you master Javascript/Jscript to a certain extent, you will find that it is N times better than VBS. The advantage lies in its free grammar, which VBS does not have. For a certain function, you only need to create a prototype or a judgment function in JS to achieve the same function. Another obvious advantage is that regular rules can be used everywhere. .

Directory:
1 Determine whether it is an array type
2 Determine whether it is a string type
3 Determine whether it is a numeric type
4 Determine whether it is a date type
5 Determine whether it is a function
6 Determine whether it is an object

shawl.qiu
2006-11-13
http://blog.csdn.net/btbtd

1 Determine whether it is an array type

linenum




2 Determine whether it is a string type

linenum




3 Determine whether it is a numeric type

linenum




4 Determine whether it is a date type

linenum




5 Determine whether it is a function

linenum


<script> <BR>//<![CDATA[ <BR> var a=[0]; <BR> document.write(isArray(a),'<br/>'); <BR> function isArray(obj){ <BR> return (typeof obj=='object')&&obj.constructor==Array; <BR> } <BR>//]]> <BR></script><script> <BR>//<![CDATA[ <BR> document.write(isString('test'),'<br/>'); <BR> document.write(isString(10),'<br/>'); <BR> function isString(str){ <BR> return (typeof str=='string')&&str.constructor==String; <BR> } <BR>//]]> <BR></script>6 Determine whether it is an object <script> <BR>//<![CDATA[ <BR> document.write(isNumber('test'),'<br/>'); <BR> document.write(isNumber(10),'<br/>'); <BR> function isNumber(obj){ <BR> return (typeof obj=='number')&&obj.constructor==Number; <BR> } <BR>//]]> <BR></script><script> <BR>//<![CDATA[ <BR> document.write(isDate(new Date()),'<br/>'); <BR> document.write(isDate(10),'<br/>'); <BR> function isDate(obj){ <BR> return (typeof obj=='object')&&obj.constructor==Date; <BR> } <BR>//]]> <BR></script>

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template