色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

基于邏輯運(yùn)算的簡單權(quán)限系統(tǒng)(實(shí)現(xiàn)) JS 版

作者: slightboy, 時(shí)間: 2006-10-17
此篇為 JS 實(shí)現(xiàn)版本, 以前作已交待原理 故不在此多做解釋
如需原理介紹 請查看 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 />");
}
注: 紅色部分為 Java 風(fēng)格寫法 不是本例所必須.
只是做一個(gè)展示, 如果你比較喜歡 Java 風(fēng)格也可以選擇這種寫法.

JavaScript技術(shù)基于邏輯運(yùn)算的簡單權(quán)限系統(tǒng)(實(shí)現(xiàn)) JS 版,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 江都市| 武山县| 喀喇| 马尔康县| 友谊县| 鱼台县| 民丰县| 楚雄市| 伊宁市| 离岛区| 甘谷县| 富阳市| 沿河| 潜山县| 舞阳县| 博罗县| 阳春市| 多伦县| 大荔县| 内江市| 江西省| 沧源| 忻州市| 西平县| 达日县| 乐清市| 年辖:市辖区| 禄丰县| 右玉县| 明光市| 鞍山市| 贡嘎县| 宁强县| 怀化市| 邻水| 新乐市| 安宁市| 醴陵市| 南昌市| 正宁县| 永福县|