Javascript simple and efficient data type series functions By shawl. qiu

Source: Internet
Author: User

Note:
Some time ago, when I got familiar with ASP VBScript, I switched to Javascript/Jscript, mainly to Jscript.
However, there is basically no difference between the two. The only difference is that Jscript has no client concept.

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

However, when you have mastered Javascript/Jscript to a certain extent, you will find that it is N times better than VBS. What is strong is that it has free syntax, and VBS does not have a certain function, in JavaScript, you only need to create prototype or a judgment function to implement the same function. the other obvious difference is that regular expressions are available everywhere.

Ah, a bunch of nonsense. Come on.

Directory:
1. Determine whether it is an array type.
2. Determine whether the string type is used.
3. Determine whether the data type is Numeric.
4. Determine if it is of the date type
5. determine whether it is a function.
6. Determine whether the object is used

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

1. Determine whether it is 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. Determine whether the string type is used.

Linenum
<Script type = "text/javascript">
// <! [CDATA [
Document. write (isString ('test'), '<br/> ');
Document. write (isString (10), '<br/> ');
Function isString (str ){
Return (typeof str = 'string') & str. constructor = string;
}
//]>
</Script>


3. Determine whether the data type is Numeric.

Linenum
<Script type = "text/javascript">
// <! [CDATA [
Document. write (isNumber ('test'), '<br/> ');
Document. write (isNumber (10), '<br/> ');
Function isNumber (obj ){
Return (typeof obj = 'number') & obj. constructor = number;
}
//]>
</Script>


4. Determine if it is of the date type

Linenum
<Script type = "text/javascript">
// <! [CDATA [
Document. write (isDate (new Date (), '<br/> ');
Document. write (isDate (10), '<br/> ');
Function isDate (obj ){
Return (typeof obj = 'object') & obj. constructor = Date;
}
//]>
</Script>


5. determine whether it is a function.

Linenum
<Script type = "text/javascript">
// <! [CDATA [
Document. write (isFunction (function test () {}), '<br/> ');
Document. write (isFunction (10), '<br/> ');
Function isFunction (obj ){
Return (typeof obj = 'function') & obj. constructor = function;
}
//]>
</Script>


6. Determine whether the object is used
<Script type = "text/javascript">

Linenum
// <! [CDATA [
Document. write (isObject (new Object (), '<br/> ');
Document. write (isObject (10), '<br/> ');
Function isObject (obj ){
Return (typeof obj = 'object') & obj. constructor = object;
}
//]>
</Script>

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.