游客:
注册
|
登录
|
帮助
网友俱乐部
»
网络编程
»
JSP教程
» 使用JScript.NET创建asp.net页面(四)
网友生活网
|
网友学堂
如何获得金币?
诚招斑竹
IP归属地查询 PR查询 收录查询 whois查询
免费超短2级域名,your.jpy.cc
传世私服
|
传奇世界私服
注册亚洲交友中心,找个人来同居吧!
免费存储空间,免费网络硬盘
‹‹ 上一主题
|
下一主题 ››
投票
交易
悬赏
活动
打印
|
推荐
|
订阅
|
收藏
标题: 使用JScript.NET创建asp.net页面(四)
trancyco
中校
UID 958
精华
4
积分 1766
帖子 824
威望 12
金币 863
热心 0
阅读权限 50
注册 2005-11-30
状态 离线
#1
使用道具
发表于 2008-7-3 00:16
资料
个人空间
短消息
加为好友
使用JScript.NET创建asp.net页面(四)
在Jscript中定义类通过类声明, 包含方法和对象和var 声明。对于类的派生通过下面两个程序的对比,你讲清楚地明白。
JScript 5.5 Code
// Simple object with no methods
function Car(make, color, year)
{
this.make = make;
this.color = color;
this.year = year;
}
function Car.prototype.GetDescription()
{
return this.year + " " + this.color + " " + this.make;
}
// Create and use a new Car object
var myCar = new Car("Accord", "Maroon", 1984);
print(myCar.GetDescription());
JScript.NET Code
// Wrap the function inside a class statement.
class Car
{
var make : String;
var color : String;
var year : int;
function Car(make, color, year)
{
this.make = make;
this.color = color;
this.year = year;
}
function GetDescription()
{
return this.year + " " + this.color + " " + this.make;
}
}
var myCar = new Car("Accord", "Maroon", 1984);
print(myCar.GetDescription());
Jscript.net还支持定义private和protected property通过GET和SET进行读写。
如下例:
class Person
{
private var m_sName : String;
private var m_iAge : int;
function Person(name : String, age : int)
{
this.m_sName = name;
this.m_iAge = age;
}
// Name 只读
function get Name() : String
{
return this.m_sName;
}
// Age 读写但是只能用SET
function get Age() : int
{
return this.m_sAge;
}
function set Age(newAge : int)
{
if ((newAge >= 0) && (newAge <= 110))
this.m_iAge = newAge;
else
throw newAge + " is not a realistic age!";
}
}
var fred : Person = new Person("Fred", 25);
print(fred.Name);
print(fred.Age);
// 这将产生一个编译错误,name是只读的。
fred.Name = "Paul";
// 这个将正常执行
fred.Age = 26;
// 这将得到一个 run-time 错误, 值太大了
fred.Age = 200;
[广告]
免费域名(Free Subdomain)
免费空间(Free hosting)
PR查询(Google Pagerank)
投票
交易
悬赏
活动
控制面板首页
编辑个人资料
积分交易
公众用户组
好友列表
个人空间管理
基本概况
流量统计
客户软件
发帖量记录
论坛排行
主题排行
发帖排行
积分排行
在线时间
管理团队
管理统计
当前时区 GMT+8, 现在时间是 2008-10-11 17:02
信产部ICP备案:
京ICP备05066424号
北京市公安局网监备案:1101050648号
Powered by
Discuz!
5.5.0
TOP
清除 Cookies
-
联系我们
-
网友俱乐部
-
Archiver
-
WAP