当前位置: 首页 > 图文教程 > 网络编程 > ASP > 使用JScript.NET创建asp.net页面(四)

ASP
用ASP编写网络传呼机
用ASP+CSS实现随机背景
ASP下载系统防盗链方法
用ASP编写下载网页中所有资源的程序
Request.ServerVariables应用
解决Asp程序的Server.CreateObject错误
ASP实现TCP端口扫描的方法
源码实例:ASP实现远程保存图片
用ASP+DLL实现WEB方式修改服务器时间
ASP使用MySQL数据库全攻略
ASP+SQL Server构建网页防火墙
教程/ASP 十天学会ASP之第二天
教程/ASP 十天学会ASP之第四天
教程/ASP 十天学会ASP之第五天
教程/ASP 十天学会ASP之第六天
教程/ASP 十天学会ASP之第七天
教程/ASP 十天学会ASP之第八天
教程/ASP 十天学会ASP之第九天
教程/ASP 十天学会ASP之第十天
关于学习ASP和编程的28个观点

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 28 ::
收藏到网摘: n/a

  在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;