考试网 >> IT认证 >> JAVA >> JAVA指导 >> 用javascript模拟C#的[Attribute]用法

用javascript模拟C#的[Attribute]用法

发布时间:2006-06-28 11:11     点击:
分页:[1] 2 3 4  下一页

  <!--用Js模拟C#的Attribute-->

执行结果:<br>

<textarea rows = "10" cols = "100" id = "output"></textarea><br>

<br>

调试信息:<br>

<textarea rows = "10" cols = "100" id = "debug"></textarea><br>

<script language="javascript">

/* 特性(Attributes)是一种崭新的声明性信息。

我们不仅可以通过特性来定义设计层面的信息

(例如help file, URL for documentation)

以及运行时(run-time)信息(例如使XML与class相联系),

而且我们还可以利用特性建立自描述(self-describing)组件。

*/

function Attribute() //Attribute 基类,可以自行定义其中的接口以扩充功能,这里只是一个简单的演示,因此留空

{

}

function TestMethod() //定义一个新的Attribute类 TestMethod,用它来给需要进行单元测试的方法提供额外信息

{

this.name = "TestMethod";

}TestMethod.prototype = new Attribute();

function TestMethodAttribute() //必需的执行方法

{

return new TestMethod();

}

function DebugOutput(bOutput) //定义一个新的Attribute类 DebugOutput,用它来指示是否在测试中输出额外的调试信息

{

this.name = "DebugOutput";

this.isAllowDebugOutput = bOutput;

}DebugOutput.prototype = new Attribute();

function DebugOutputAttribute(bOutput) //必需的执行方法

{

return new DebugOutput(bOutput);

}

Function.__captureAttributes = function(obj)

{

var attributeDef = /\[\w+\].*\n.*(?=\=[\s]*function)/g;
分页:[1] 2 3 4  下一页
版权申明:未经书面授权请勿转载本站信息!!作品版权归所属媒体与作者所有!!
发表评论: 匿名发表 用户名: 查看评论
您将承担一切因您的行为、言论而直接或间接导致的民事或刑事法律责任
留言板管理人员有权保留或删除其管辖留言中的任意内容
本站提醒:不要进行人身攻击。谢谢配合。
在本站搜索相关信息
2003-2005 Ksw123.com All Rights Reserved. - TOP
Copyright © 2006 Ksw123.com. All rights reserved.中国考题网 版权所有