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

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

作者: slightboy, 時間: 2006-10-17
此篇為 JS 實現(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)格寫法 不是本例所必須.
只是做一個展示, 如果你比較喜歡 Java 風(fēng)格也可以選擇這種寫法.

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

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

主站蜘蛛池模板: 阜阳市| 吴忠市| 南昌市| 宜兴市| 镶黄旗| 双牌县| 湖州市| 盐城市| 龙山县| 夏邑县| 泰宁县| 东海县| 九台市| 始兴县| 甘孜县| 长沙县| 兴隆县| 全椒县| 新郑市| 新兴县| 道真| 修文县| 西峡县| 南雄市| 红桥区| 涪陵区| 黄大仙区| 汶川县| 青浦区| 莲花县| 大英县| 依兰县| 德令哈市| 延寿县| 连城县| 射洪县| 丹巴县| 湘阴县| 松江区| 彭州市| 南皮县|