Author: slightboy, time: 2006-10-17
This is the JS implementation version. I have previously explained the principles, so I will not explain it here.
For more information, see VBS.
Var PermissionType =
{
Read: 1,
Write: 2,
Delete: 4
}
Function PermissionSetComponent (value)
{
This. Value = value;
This. getRead = function ()
{
Return this. getValue (PermissionType. Read );
}
This. setRead = function (value)
{
This. setValue (PermissionType. Read, value );
}
This. Read = function ()
{
If (arguments. length> 0)
This. setValue (PermissionType. Read, arguments [0]);
Else
Return this. getValue (PermissionType. Read );
}
This. Write = function ()
{
If (arguments. length> 0)
This. setValue (PermissionType. Write, arguments [0]);
Else
Return this. getValue (PermissionType. Write );
}
This. Delete = function ()
{
If (arguments. length> 0)
This. setValue (PermissionType. Delete, arguments [0]);
Else
Return this. getValue (PermissionType. Delete );
}
This. getValue = function (permissionType)
{
Return (this. Value & permissionType) = permissionType;
}
This. setValue = function (permissionType, value)
{
If (value)
This. Value | = permissionType;
Else
This. Value & = ~ PermissionType;
}
}
Var PermissionSet = new PermissionSetComponent (0 );
W ("Read :");
PermissionSet. Read (false );
W (PermissionSet. Value + "" + PermissionSet. Read ());
PermissionSet. Read (true );
W (PermissionSet. Value + "" + PermissionSet. Read ());
W ("Write :");
PermissionSet. Write (false );
W (PermissionSet. Value + "" + PermissionSet. Write ());
PermissionSet. Write (true );
W (PermissionSet. Value + "" + PermissionSet. Write ());
W ("Delete :");
PermissionSet. Delete (false );
W (PermissionSet. Value + "" + PermissionSet. Delete ());
PermissionSet. Delete (true );
W (PermissionSet. Value + "" + PermissionSet. Delete ());
Function w (o)
{
Response. Write (o + "<br/> ");
}
Note: The red part is written in java style and is not required in this example.
This is just a demonstration. If you prefer the java style, you can choose this method.