龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

利用MS AJAX注册Javascript命名空间并创建类

时间:2013-03-06 14:58来源:未知 作者:admin 点击:
分享到:
一、为页面添加一个ScriptManager控件 二、注册命名空间:Type.registerNamespace("Demo"); 三、为类添加构造函数、属性、方法 Demo.sample=function(){} 四、注册类 Demo.Person.registerClass('Demo.sample ', nu

一、为页面添加一个ScriptManager控件

二、注册命名空间:Type.registerNamespace("Demo");

三、为类添加构造函数、属性、方法

Demo.sample=function(){}

四、注册类

Demo.Person.registerClass('Demo.sample ', null, Sys.IDisposable);

下面是一个具体的实例:

Namespace.js

Type.registerNamespace("Demo");
Demo.Person = function(firstName, lastName, emailAddress) {
this._firstName = firstName;
this._lastName = lastName;
this._emailAddress = emailAddress;
}
Demo.Person.prototype = {
getFirstName: function() {
return this._firstName;
},
getLastName: function() {
return this._lastName;
},
getName: function() {
return this._firstName + ' ' + this._lastName;
},
dispose: function() {
alert('bye ' + this.getName());
}
}
Demo.Person.registerClass('Demo.Person', null, Sys.IDisposable);

Namespace.aspx代码:
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


Namespace






This example creates an instance of the Person class
and puts it in the "Demo" namespace.


type="button" onclick="return OnButton1Click()" />
精彩图集

赞助商链接