Simulate Enum by shawl. Qiu in Javascript

Source: Internet
Author: User
Simulate Enum by shawl. Qiu in Javascript

Note:
This simulation is simple, but because JS programs are usually very small, basically no data type like Enum is needed...

For more information, see shawl. Qiu JavaScript hash table/hashtable V1.0.
Http://blog.csdn.net/btbtd/archive/2007/06/28/1669636.aspx

Shawl. Qiu
2007-08-22
Http://blog.csdn.net/btbtd

Content: // shawl. Qiu JavaScript document
/* Optional /*-----------------------------------------------------------------------------------*/
* Shawl. Qiu Enum class V1.0
/* Optional /*-----------------------------------------------------------------------------------*/
// ----------------------------------- Begin class Enum ()-------------------------------//
Function Enum ()
{// Shawl. Qiu code: return object
// -------------------------------------- Begin private variable
VaR Arg = arguments;
// -------------------------------------- Begin private Method
Function fgetenum ()
{
VaR this = this;
VaR arglen = Arg. length;
VaR Index = 0;

If (arglen> 0)
{
For (VAR I = 0; I <arglen; I ++)
{
Arg [I] + = "";
Arg [I] = Arg [I]. Replace (// s +/g ,"");
If (ARG [I]. indexof ("=")>-1)
{
VaR tempar = Arg [I]. Split ("= ");
If (tempar. length! = 2)
{
Throw new error (["Enumeration type:", Arg [I], "initialization error! "]. Join (''));
}
VaR itemp = parseint (tempar [1]);
If (isnan (itemp ))
{
Throw new error (["Enumeration type:", Arg [I], "initial value error! "]. Join (''));
}

This [tempar [0] = itemp;

Index = ++ itemp;
}
Else
{
This [Arg [I] = index ++;
}
}
}
Else
{
Ffatalerror ("the enumeration type must have an initial parameter! ");
}
Return this;
}

Function ffatalerror (smsg)
{// Shawl. Qiu code: void return
If (! Smsg) smsg = "a serious error occurs. Terminate the program now! ";
Throw new error (smsg );
} // End function ffatalerror
// -------------------------------------- End private Method

// -------------------------------------- Begin initer
Return new fgetenum ();
// -------------------------------------- End initer
} // Shawl. Qiu code
// ----------------------------------- End class Enum ()---------------------------------//

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.