动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   .Net → 阅读文章

 使用JScript.NET创建asp.net页面(四)

作者:chenyangasp 来源:chinaasp 
阅读 3234 人次 , 2001-8-17 

在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;
  
 本文TagsC#  组网  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:使用JScript.NET创建asp.net页面(五)
· 下一篇:使用JScript.NET创建asp.net页面(三)
· 细细品味ASP.NET (一)
· Servlet 是什么?
· .net中的事务处理(一)
· ASP.NET虚拟主机的重大安全隐患(四)
· ASP.NET程序中用Repeater实现分页


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077