惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
博客园_首页
H
Help Net Security
WordPress大学
WordPress大学
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
罗磊的独立博客
博客园 - 三生石上(FineUI控件)
B
Blog
I
InfoQ
SecWiki News
SecWiki News
T
Tailwind CSS Blog
Spread Privacy
Spread Privacy
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
Vulnerabilities – Threatpost
N
Netflix TechBlog - Medium
P
Palo Alto Networks Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
K
Kaspersky official blog
M
MIT News - Artificial intelligence
S
Schneier on Security
T
Threat Research - Cisco Blogs
F
Fortinet All Blogs
Cyberwarzone
Cyberwarzone
Scott Helme
Scott Helme
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The Cloudflare Blog
Recent Announcements
Recent Announcements
Security Latest
Security Latest
G
GRAHAM CLULEY
IT之家
IT之家
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
腾讯CDC
Google DeepMind News
Google DeepMind News
V
V2EX
S
Securelist
TaoSecurity Blog
TaoSecurity Blog
B
Blog RSS Feed
S
SegmentFault 最新的问题
博客园 - 叶小钗
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
F
Full Disclosure

博客园 - jayu

Windows 资源管理中 创建无文件名只有扩展名文件 CoreOS Hyper-V 安装 RancherOS Hyper-V 安装 代码片段 MSSQL 2005 分页分析及优化 泛型类型的返回 招 .Net 网站程序员, Flash 程序员 上海盛大网络浩方在线招聘网站程序 ACS 20070412 TODO JSmarty ACS 20070108 更新 Alienwave.CommunityServer 20070103 更新 基于逻辑运算的简单权限系统(原理,设计,实现) VBS 版 ACS 社区系统演示地址 Python 2.5 发布 Visual Studio 2005 SDK version 3.0 道德沦丧 还是意识淡薄 Microsoft Expression Web Beta 1 《星际之剑》(Sword of the Stars)CLONE版
基于逻辑运算的简单权限系统(实现) JS 版
jayu · 2006-10-17 · via 博客园 - jayu

作者: slightboy, 时间: 2006-10-17

此篇为 JS 实现版本, 以前作已交待原理 故不在此多做解释

如需原理介绍 请查看 VBS 版.

 首发于: http://cs.alienwave.cn/Topic/356.aspx

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 风格写法 不是本例所必须.

只是做一个展示, 如果你比较喜欢 java 风格也可以选择这种写法.