快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

使用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;



返回类别: 教程
上一教程: ASP.NET超凡的代码控制(一)
下一教程: 用Js判定输入的时间是否有效 

您可以阅读与"使用JScript.NET创建asp.net页面(四)"相关的教程:
· 使用JScript.NET创建asp.net页面(六)
· 使用JScript.NET创建asp.net页面(二)
· 使用JScript.NET创建asp.net页面(七)
· 使用JScript.NET创建asp.net页面(三)
· 使用JScript.NET创建asp.net页面(一)
    微笑服务 优质保证 索取样品