首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP.NET > Ms Ajax Lib-> Object 类型扩展
【标  题】:Ms Ajax Lib-> Object 类型扩展
【关键字】:Ms,Ajax,Lib-,Object
【来  源】:http://blog.csdn.net/chsword/archive/2007/02/28/1517228.aspx

Ms Ajax Lib-> Object 类型扩展

Object 类型扩展

提供了基于 ECMAScript (JavaScript) 的Object 对象的扩展.

命名空间: 无. 本扩展类型是全局型的不属于任意一命名空间。

继承: 无.

语法

var objectVar = new Object();

成员扩展

名称

说明

Object.getType 函数

返回一个指定类型实例.

Object.getTypeName 函数

返回当前运行对象的类型名。

备注

Object 扩展是Microsoft AJAX库的一部分。 它为JavaScript 类库添加了许多功能,并且使之与.net更加亲和。 Object类型扩展提供了更多关于类型的描述与操作方法.

更多关于 JavaScript 类的扩展类型的消息, 请参见 Object Object in the JScript Language Reference.

下面的示例展示了如何使用Object类型扩展,使用getType 扩展函数来创建并引用一个实例。它也用到了getTypeName 扩展函数。

CS

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
</form>
</body>
</html>

<script type="text/javascript">

Type.registerNamespace('Samples');

// Define and register a Samples.Rectangle class.
Samples.Rectangle = function(width, height)
{
this._width = width;
this._height = height;
}

Samples.Rectangle.prototype.getWidth = function() {
return (this._width === undefined) ? null : this._width;
}

Samples.Rectangle.prototype.getHeight = function() {
return (this._width === undefined) ? null : this._height;
}

Samples.Rectangle.registerClass('Samples.Rectangle');


// Define and register a Samples.Square class.
Samples.Square = function(length)
{
this._length = length;
}

Samples.Square.prototype.getLength = function() {
return (this._length === undefined) ? null : this._length;
}

Samples.Square.prototype.setLength = function(length) {
this._length = length;
}

Samples.Square.registerClass('Samples.Square');


// Create instances of Square and Rectangle and discover their types.
Samples.testObjectReflection = function()
{
var width = 200;
var height = 100;
var a = new Samples.Rectangle(width, height);

var length = 50;
var b = new Samples.Square(length);

var name = Object.getTypeName(a);
document.write("The type name of object \"a\" is: " + name + "<\p>");

var isSquare = Samples.Rectangle.isInstanceOfType(b)
document.write("Object \"b\" is an instance of type Square: " + isSquare + "<\p>");

var c = Object.getType(b);
name = Object.getTypeName(c);
document.write("The type name of object \"c\" is: " + name + "<\p>");

var isSquare = Samples.Square.isInstanceOfType(c);
if (isSquare)
{
var newLength = a.getWidth();
c.setLength(newLength);
document.write("Object \"c\" is a Square with a length of: " + c.getLength() + "<\p>");
}
}

// Run the sample.
Samples.testObjectReflection();

</script>

VB

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server" ID="ScriptManager1">
</asp:ScriptManager>
</form>
</body>
</html>

<script type="text/javascript">

Type.registerNamespace('Samples');

// Define and register a Samples.Rectangle class.
Samples.Rectangle = function(width, height)
{
this._width = width;
this._height = height;
}

Samples.Rectangle.prototype.getWidth = function() {
return (this._width === undefined) ? null : this._width;
}

Samples.Rectangle.prototype.getHeight = function() {
return (this._width === undefined) ? null : this._height;
}

Samples.Rectangle.registerClass('Samples.Rectangle');


// Define and register a Samples.Square class.
Samples.Square = function(length)
{
this._length = length;
}

Samples.Square.prototype.getLength = function() {
return (this._length === undefined) ? null : this._length;
}

Samples.Square.prototype.setLength = function(length) {
this._length = length;
}

Samples.Square.registerClass('Samples.Square');


// Create instances of Square and Rectangle and discover their types.
Samples.testObjectReflection = function()
{
var width = 200;
var height = 100;
var a = new Samples.Rectangle(width, height);

var length = 50;
var b = new Samples.Square(length);

var name = Object.getTypeName(a);
document.write("The type name of object \"a\" is: " + name + "<\p>");

var isSquare = Samples.Rectangle.isInstanceOfType(b)
document.write("Object \"b\" is an instance of type Square: " + isSquare + "<\p>");

var c = Object.getType(b);
name = Object.getTypeName(c);
document.write("The type name of object \"c\" is: " + name + "<\p>");

var isSquare = Samples.Square.isInstanceOfType(c);
if (isSquare)
{
var newLength = a.getWidth();
c.setLength(newLength);
document.write("Object \"c\" is a Square with a length of: " + c.getLength() + "<\p>");
}
}

// Run the sample.
Samples.testObjectReflection();

</script>

 
HTML标签解释:【上一篇】
JS集锦:【下一篇】
【相关文章】
  • AJAX初探
  • VS2003在安装MSSCCI 后无法访问原先的VSS
  • ASP.NET AJAX和SharePoint
  • HP MSA1500存储安装调试
  • 连接远程SQL Server MSDE失败的原因
  • AJAX 设计模式
  • MsAjax Lib-> Array.enqueue 函数
  • MsAjax Lib-> Array.dequeue 函数
  • MsAjax Lib-> Array.forEach 函数
  • MsAjax Lib-> Array.indexOf 函数
  • 【随机文章】
  • 谁知道c++中的char ** 在C#中一般用什么类型
  • 服务器时钟自动校准
  • const与*的位置----摘抄
  • 使用循环/线程模拟实现对象间事件传递(杀牛游戏)
  • 能生成这个类的一个对象嘛???
  • 设计新一代的网游——第二章(网游现存问题及解决方法)
  • 无缝滚动代码
  • 修炼成合格的程序员(转帖)
  • 【建议】关于在博客园设置“建议专区”的建议
  • 系统安全初始化
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.