基于邏輯運(yùn)算的簡(jiǎn)單權(quán)限系統(tǒng)(實(shí)現(xiàn)) JS 版
更新時(shí)間:2007年03月24日 00:00:00 作者:
作者: slightboy, 時(shí)間: 2006-10-17
此篇為 JS 實(shí)現(xiàn)版本, 以前作已交待原理 故不在此多做解釋
如需原理介紹 請(qǐng)查看 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)格也可以選擇這種寫法.
此篇為 JS 實(shí)現(xiàn)版本, 以前作已交待原理 故不在此多做解釋
如需原理介紹 請(qǐng)查看 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)格也可以選擇這種寫法.
您可能感興趣的文章:
- js的邏輯運(yùn)算符 ||
- JavaScript中的邏輯判斷符&&、||與!介紹
- js比較和邏輯運(yùn)算符的介紹
- javascript中負(fù)數(shù)算術(shù)右移、邏輯右移的奧秘探索
- 用JavaScript實(shí)現(xiàn)一個(gè)代碼簡(jiǎn)潔、邏輯不復(fù)雜的多級(jí)樹
- js針對(duì)ip地址、子網(wǎng)掩碼、網(wǎng)關(guān)的邏輯性判斷
- JSP教程之使用JavaBean完成業(yè)務(wù)邏輯的方法
- 詳解JavaScript邏輯And運(yùn)算符
- 詳解JavaScript邏輯Not運(yùn)算符
- Javascript中常見的邏輯題和解決方法
相關(guān)文章
JavaScript實(shí)現(xiàn)簡(jiǎn)易購(gòu)物車最全代碼解析(ES6面向?qū)ο?
這篇文章主要為大家詳細(xì)介紹了JavaScript實(shí)現(xiàn)簡(jiǎn)易購(gòu)物車最全代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09JavaScript對(duì)象字面量和構(gòu)造函數(shù)原理與用法詳解
這篇文章主要介紹了JavaScript對(duì)象字面量和構(gòu)造函數(shù),結(jié)合實(shí)例形式分析了JavaScript對(duì)象字面量和構(gòu)造函數(shù)相關(guān)概念、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2020-04-04JS獲取CSS樣式(style/getComputedStyle/currentStyle)
這篇文章主要為大家介紹了JS獲取CSS樣式的方法,介紹了CSS樣式的三種分類情況,對(duì)獲取樣式做一個(gè)簡(jiǎn)單的封裝,感興趣的小伙伴們可以參考一下2016-01-01最全正則表達(dá)式總結(jié):驗(yàn)證QQ號(hào)、手機(jī)號(hào)、Email、中文、郵編、身份證、IP地址等
這篇文章主要介紹了最全正則表達(dá)式:驗(yàn)證QQ號(hào)、手機(jī)號(hào)、Email、中文、郵編、身份證、IP地址等,通過語(yǔ)法介紹作用表達(dá)式等詳細(xì)解釋了正則表達(dá)式的使用,具體操作步驟大家可查看下文的詳細(xì)講解,感興趣的小伙伴們可以參考一下。2017-08-08js實(shí)現(xiàn)滾動(dòng)條自動(dòng)滾動(dòng)
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)滾動(dòng)條自動(dòng)滾動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-12-12JS實(shí)現(xiàn)仿微博可關(guān)閉彈出層效果
這篇文章主要介紹了JS實(shí)現(xiàn)仿微博可關(guān)閉彈出層效果,涉及JavaScript彈出窗口的設(shè)置及頁(yè)面元素動(dòng)態(tài)操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-09-09