JavaScript simple and efficient Judge data type series functions by Shawl.qiu_javascript tips

Source: Internet
Author: User
Tags cdata numeric
Description
Some time ago when the ASP VBScript mastered the same time, instead of learning javascript/jscript, mainly to learn Jscript.
But there is no difference between the two, except that Jscript does not have a client concept.

In the beginning, I found some useful functions of VBS Js not much, FormatNumber ah IsArray ah isDate ah, and so on.
There are also date objects are very strange, can not directly Gaga to reduce, to set*** ...

But to javascript/jscript mastered to a certain extent, will find him than VBS strong N times, strong place lies in his free grammar, VBS does not have a certain function, in Js as long as a prototype or build a judgment function can achieve the same function completely. Another strong point is that it is available everywhere.

Yes, just a bunch of crap.

Directory:
1 determining whether an array type
2 determining whether a string type
3 Determining whether a numeric type
4 Determine whether the date type
5 judge whether it is a function
6 Determine whether or not an object

Shawl.qiu
2006-11-13
Http://blog.csdn.net/btbtd

1 determining whether an array type

LineNum
<script type= "Text/javascript" >
<! [cdata[
var a=[0];
document.write (IsArray (a), ' <br/> ');
function IsArray (obj) {
Return (typeof obj== ' object ') &&obj.constructor==Array;
}
]]>
</script>


2 determining whether a string type

LineNum
<script type= "Text/javascript" >
<! [cdata[
document.write (isstring (' Test '), ' <br/> ');
document.write (isstring), ' <br/> ';
function isstring (str) {
Return (typeof str== ' string ') &&str.constructor==String;
}
]]>
</script>


3 Determining whether a numeric type

LineNum
<script type= "Text/javascript" >
<! [cdata[
document.write (isnumber (' Test '), ' <br/> ');
document.write (Isnumber), ' <br/> ';
function Isnumber (obj) {
Return (typeof obj== ' number ') &&obj.constructor==Number;
}
]]>
</script>


4 Determine whether the date type

LineNum
<script type= "Text/javascript" >
<! [cdata[
document.write (IsDate (new Date), ' <br/> ');
document.write (isDate), ' <br/> ';
function IsDate (obj) {
Return (typeof obj== ' object ') &&obj.constructor==Date;
}
]]>
</script>


5 judge whether it is a function

LineNum
<script type= "Text/javascript" >
<! [cdata[
document.write (isfunction (function test () {}), ' <br/> ';
document.write (isfunction), ' <br/> ';
function Isfunction (obj) {
Return (typeof obj== ' function ') &&obj.constructor==Function;
}
]]>
</script>


6 Determine whether or not an object
<script type= "Text/javascript" >

LineNum
<! [cdata[
document.write (IsObject (new Object), ' <br/> ');
document.write (IsObject), ' <br/> ';
function IsObject (obj) {
Return (typeof obj== ' object ') &&obj.constructor==Object;
}
]]>
</script>
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.