国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發(fā)設計 > 正文

使用JScript.NET創(chuàng)建asp.net頁面(四)

2019-11-18 20:36:22
字體:
來源:轉載
供稿:網友
在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";
// 這個將正常執(zhí)行
fred.Age = 26;
// 這將得到一個 run-time 錯誤, 值太大了
fred.Age = 200;



發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 武陟县| 南皮县| 仁布县| 旬邑县| 墨玉县| 于都县| 维西| 长寿区| 本溪市| 富平县| 台中市| 恩施市| 文昌市| 石渠县| 安西县| 福海县| 华池县| 新余市| 肥西县| 商丘市| 泗洪县| 肇庆市| 肥东县| 乌兰县| 磐安县| 桃江县| 县级市| 巍山| 白朗县| 开远市| 峨边| 乐东| 平定县| 淄博市| 静安区| 乌拉特中旗| 徐闻县| 阳原县| 诏安县| 织金县| 连江县|